将__attribute __((objc_requires_super))与协议一起使用

Tep*_*har 7 objective-c ios

我有这样的事情:

@protocol MyProtocol <NSObject>

- (void)oneMethod;

@end
Run Code Online (Sandbox Code Playgroud)

.

@interface BaseClassWithProtocol : NSObject <MyProtocol>

@end
Run Code Online (Sandbox Code Playgroud)

.

@interface ChildClassWithProtocol : BaseClassWithProtocol

@end
Run Code Online (Sandbox Code Playgroud)

BaseClassWithProtocol已经实现了oneMethod,如果ChildClassWithProtocoloneMethod实现中没有调用super,我想显示警告.

但我不知道我应该在哪里写__attribute__((objc_requires_super)).

在.h中重新定义oneMethod看起来很愚蠢时,不支持在协议中编写它.

那么有什么标准方法可以解决这个问题吗?

Ken*_*ses 7

呼叫超级的要求是强加的BaseClassWithProtocol.它不是协议的一部分.当然,有些班级可以实施,MyProtocol但没有强制要求.这是协议的本质.它们强加接口,而不是实现.

因此,BaseClassWithProtocol使用属性重新声明方法对我来说似乎是完全合理的.不知道为什么它"看起来很愚蠢".