未调用[super method]时发出警告 [英] Give warning when [super method] is not called

查看:84
本文介绍了未调用[super method]时发出警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不使用ARC时,如果未在dealloc方法中调用[super dealloc],则会收到警告.

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.

有什么想法吗?

推荐答案

最近的llvm版本添加了一个属性,该属性指示子类必须调用super:

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

这篇关于未调用[super method]时发出警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆