开发者

Category implementation showing possible issue

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

@implementati开发者_运维百科on NSArray

- (void)letsPlay {
    [self runMethod]; // says -runMethod might be missing
}

@end


As long as the compiler sees the declaration of the method run prior to the call of the method, you will not see that error.

Usually, private categories are done like:

#import "M.h"
@interface M(PrivateGunk)
.... declarations here ...
@end

@implementation M
@end

@implementation M(PrivateGunk)
.... impl here ...
@end

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....

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜