Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Objective-c: How can I require override and not call super?

I guess this is solved by writing a @protocol.

But I'm hungry for knowledge. Is there some flag or other way to require subclasses to override specific methods and not call super? Like the opposite of NS_REQUIRES_SUPER / objc_requires_super?

like image 430
hfossli Avatar asked Mar 10 '14 10:03

hfossli


1 Answers

I do that in code not using any flags.
- I add assertion in the method of the super class that needs to be overridden in case this method is get called

Here I have a class that have a method fetchUserData that should be overridden by the child class

- (void)fetchUserData
{
    NSString *descrip = [NSString stringWithFormat:@"child implementation for method:%@ :  %@",NSStringFromSelector(_cmd),  NSStringFromClass([self class])
    NSAssert(NO, descrip);
}
like image 91
Basheer_CAD Avatar answered Oct 21 '22 16:10

Basheer_CAD