AWF4vk
AWF4vk

Reputation: 5890

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

@implementation NSArray

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

@end

Upvotes: 0

Views: 286

Answers (1)

bbum
bbum

Reputation: 162722

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

Upvotes: 2

Related Questions