I have a class Class, that has a private category (@interface Class (Private)). The category has a method named “-run”.
But, when XCode is showing that [classInstance run]; “may nto respond to -run”. I’m not sure why this is. The method runs fine, and is declared in the same .m file as the actual class. Right above the actual class implementation.
Any ideas what I’m doing wrong?
Here’s my entire .m file. I know it’s extending NSArray at the moment, but I made it that way to show the example without any other .h dependency.
#import <Foundation/Foundation.h>
@implementation NSArray (Private)
-(void)runMethod {}
@end
@implementation NSArray
- (void)letsPlay {
[self runMethod]; // says -runMethod might be missing
}
@end
As long as the compiler sees the declaration of the method
runprior to the call of the method, you will not see that error.Usually, private categories are done like:
Though many of us have moved to sticking the private stuff in a class extension at the top of the file, which also allows for @properties, ivars, etc….