Well, this is quite a weird issue. (I just hope it has something to do with my not-playing-that-much-with-Cocoa-for-a-while, or else…)
So, the issue is quite straightforward :
- I’m using Xcode 4.3.3 (a very simple test project – 10.7 SDK – no ARC)
- I’m creating a Category on some Class (e.g.
NSProgressIndicator) - I’m including the appropriate header file
- When trying to use any of my Category’s methods (however, it still shows up in the dropdown of available commands), I’m getting an error :
[NSProgressIndicator start]: unrecognized selector sent to instance
0x7f9f4b91a0a0
The code
(as an example – it has happened with other (100-times tested) categories):
#import <Foundation/Foundation.h>
@interface NSProgressIndicator (NSProgressIndicator_Functions)
- (void)start;
- (void)stop;
@end
#import "NSProgressIndicator+Functions.h"
@implementation NSProgressIndicator (NSProgressIndicator_Functions)
- (void)start
{
[self setHidden:NO];
[self startAnimation:nil];
}
- (void)stop
{
[self setHidden:YES];
[self stopAnimation:nil];
}
@end
Any ideas?
To expand my comment into a real answer:
Make sure the category’s implementation (.m) file is included in your target’s Compile Sources build phase. Importing the header is enough to tell the compiler that there is a category on NSProgressIndicator which adds a
-startmethod. Unless the category’s implementation is actually compiled and linked into the finished binary (or the method implementation is added at runtime, etc), NSProgressIndicator won’t actually respond to thestartmessage at runtime. Because of Objective-C’s dynamic message send behavior, there’s no way the compiler can tell at compile time whether or not NSProgressIndicator is actually going to respond to that message, which is why you don’t get a warning or an error.