I have created a protocol that my classes need to implement, and then factored out some common functionality into a base class, so I did this:
@protocol MyPr
You could conceivably do something like this:
@implementation Base
- (void)bar
{
if ([self class] == [Base class]) {
[self doesNotRecognizeSelector:_cmd];
}
}
@end
That way, you have an implementation, but by default it raises an exception. However, if a derived class accidentally calls [super bar]
or does not override bar
, then the exception won't be raised. If that's not what you want, you could just shorten it to:
@implementation Base
- (void)bar
{
[self doesNotRecognizeSelector:_cmd];
}
@end
In which case, an exception will be raised, even if a subclass calls [super bar]
or does not override bar
.