3

.h

#import <Foundation/Foundation.h>
#import "Person.h"

extern NSString *const kRemindersWeekly;
extern NSString *const kRemindersDaily;

@interface Reminders : NSObject

+(void)setRemindersForPerson: (Person*) person;
+(void)setEightDayReminder;

@end

.m

#import "Reminders.h"
@implementation Reminders

NSString *const kRemindersWeekly    = @"WEEKLY";
NSString *const kRemindersDaily     = @"DAILY";

+ (void) setRemindersForPerson: (Person*) person
{
    // some code
}

+(void)setEightDayReminder
{
    // some more code
}


@end

when I call:

[Reminders setRemindersForPerson: p];

this always works fine. When I call:

[Reminders setEightDayReminder];

I get:

+[Reminders setEightDayReminder]: unrecognized selector sent to class 0xe1b58

Also, [Reminders setRemindersForPerson:]; calls [Person setEightDayReminder] without any problems. Builds fine and Command clicking on functions in XCode shows it.I think everything is in order as it takes me to the appropriate places.

Must be missing something obvious?! Pulling my hair out.

Anil
  • 2,430
  • 3
  • 37
  • 55
lewis
  • 2,936
  • 2
  • 37
  • 72
  • from where do you call the setEightDayReminder method when it crashes? – ophychius Nov 28 '12 at 10:36
  • use self instead of Reminders when you call a function – Sharanya K M Nov 28 '12 at 10:36
  • @Sharanya, it is a static method, self refers to an instance that does not exist. I static method is called on the class, Reminders, not on an instance 'self' – ophychius Nov 28 '12 at 10:38
  • 2
    try to change mathod name mySetEightDayReminder instead of setEightDayReminder. – Nookaraju Nov 28 '12 at 10:43
  • 3
    And for clarification those are not static methods they are class methods. There is a difference see http://stackoverflow.com/questions/8089186/objective-c-difference-between-class-method-and-static-method – Gwynant Jones Nov 28 '12 at 11:14
  • its a class method.. and when you are using/calling a class method in the same class, you should use self. If you are calling a class method of some class in another class then you do what you have done.. – Sharanya K M Nov 28 '12 at 11:27
  • Do you perchance have a property named "eightDayReminder"? – Hot Licks Apr 29 '14 at 14:32

2 Answers2

2

I had a very similar problem, and the cause was that I had a category in which I forgot to specify the category in the @implementation block, effectively overriding original implementation with the "new" one.

Thus, if you have a category MyCategory on class SomeClass, make sure that its implementation looks like:

@interface SomeClass (MyCategory) ...

and not like:

@interface SomeClass ...
Lukas Kalinski
  • 2,213
  • 24
  • 26
1

There is one simple way to debug it - put a breakpoint there and watch what's happening.

See Creating breakpoint in Xcode for unrecognized selector how to create a breakpoint for unrecognized selectors. Your stack trace should tell you everything you need to know.

Probably you should add your calling code as well.

Community
  • 1
  • 1
Sulthan
  • 128,090
  • 22
  • 218
  • 270