I have derived from a 3rd party class, and when I attempt to call a method in the base class, I get the x may not respond to y compiler warning.
How can I remove the warning?
Repro:
@interface ThirdPartyBaseClass : NSObject {}
+(id)build;
-(void)doStuff;
@end
@implementation ThirdPartyBaseClass
+(id) build{
return [[[self alloc] init] autorelease];
}
-(void)doStuff{
}
@end
@interface MyDerivedClass : ThirdPartyBaseClass {}
+(id)buildMySelf;
@end
@implementation MyDerivedClass
+(id)buildMySelf{
self = [ThirdPartyBaseClass build];
[self doStuff]; // compiler warning here - 'MyDerivedClass' may not respond to '+doStuff'
return self;
}
@end
Thanks!
In a class method (preceded by the ‘+’), ‘self’ is not an instance of the class; ‘self’ is the Class object, which only responds to Class methods, not instance methods. If you’re building an instance so you can call
doStuffon it and return it, you’ll need to use a separate variable: