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?
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?
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);
}
There are some things here that should be useful.
Specifically subclassResponsibility:
EDIT: Good point in the comments - GNUStep != Foundation. In other words, the methods on the page I linked to should be used with caution. However, I've personally used subclassResponsibility:
and it works.
If I understand this right you're essentially asking how to make an abstract class... forcing subclasses to implement methods.
Check out : Creating an abstract class in Objective-C
In short, have the method throw an exception.