Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
454 views
Welcome To Ask or Share your Answers For Others

1 Answer

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...