Objective-C inheritance; calling overriden method from superclass?
- by anshuchimala
Hello,
I have an Objective-C class that has a method that is meant to be overridden, which is uses in a different method. Something like this:
@interface BaseClass
- (id)overrideMe;
- (void)doAwesomeThings;
@end
@implementation BaseClass
- (id)overrideMe {
[self doesNotRecognizeSelector:_cmd];
return nil;
}
- (void)doAwesomeThings {
id stuff = [self overrideMe];
/* do stuff */
}
@end
@interface SubClass : BaseClass
@end
@implementation SubClass
- (id)overrideMe {
/* Actually do things */
return <something>;
}
@end
However, when I create a SubClass and try to use it, it still calls overrideMe on the BaseClass and crashes due to doesNotRecognizeSelector:. (I'm not doing a [super overrideMe] or anything stupid like that).
Is there a way to get BaseClass to call the overridden overrideMe?