Methods in super that will be subclassed anyway (Cocoa)-Collection of common programming errors
My solution was a little weird, but here it is:
@protocol JSDog
- (void)yipe;
@end
@interface JSDog : NSObject
@end
@implementation JSDog
+ (void)initialize {
if ([self isSubclassOfClass:[JSDog class]] && ![self conformsToProtocol:@protocol(JSDog)]) {
NSAssert(false, @"Subclasses of JSDog must conform to .");
}
}
@end
Having a protocol with the same name as a class is precedented in NSObject. Because methods in a formal protocol a by default @required, you will be protected on both ends: in compile-time, if your JSDog subclass purports to conform to , but doesn’t implement -yipe, you will receive an error; at runtime, if your subclass does not claim to conform with , you will receive a warning when the subclass is instantiated.