When not using ARC, you get a warning when not calling [super dealloc] in your dealloc method.
I\'m trying to implement something similar with a class that gets subc
NS_REQUIRES_SUPER
is the modern expression for
__attribute__((objc_requires_super))
See bbum's answer for a direct way to tell the compiler that subclassers must call super
.
What Apple does generally is to provide a hook, like viewDidLoad
. Apple doesn't do any work in the base -[UIViewController viewDidLoad]
. It's an empty method. Instead, Apple does its work elsewhere, in some private method that you're not allowed to override, and calls your viewDidLoad
from that method. So even if you forget to call [super viewDidLoad]
in your UIViewController
subclass, all of Apple's work still gets done.
Perhaps you can revise your API to use a similar pattern.
Recent versions of llvm have added an attribute that indicates that subclasses must call super:
@interface Barn:NSObject
- (void)openDoor NS_REQUIRES_SUPER;
@end
@implementation Barn
- (void) openDoor
{
;
}
@end
@interface HorseBarn:Barn
@end
@implementation HorseBarn
- (void) openDoor
{
;
}
@end
Compiling the above produces the warning:
Method possibly missing a [super openDoor] call