Error “unrecognized selector” while trying to call extended interface method
July 28th, 2011
You know you can extend interface by adding some method using category in Objective-C with code similar to this:
@interface NSString (MyCategory) -(void) myMethod:(NSString*)name; @end
You should put this code into header file (for example NSString+MyCategory.h), then implement method in implementation file (NSString+MyCategory.m). Then you try to call myMethod for any NSString instance. But you get error unrecognized selector myMethod, you can think “hm….., why?!!! i’m linked header file “ (with #import “NSString+MyCategory.h”), even XCode IDE gives you myMethod automatically, but in some reason it does not work. So solution is very simple you just need to import implementation file along with header file #import “NSString+MyMethod.h”. I can not explain why, but in some way compiler does not link implementation file automatically.



