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 subclassed often to warn the person implementing the subclass when they don't call super.
Any ideas?
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With