我指的是此链接(使用谷歌翻译阅读) - about NS_PROTOCOL_REQUIRES_EXPLICIT_IMPLEMENTATION
我试图让NS_PROTOCOL_REQUIRES_EXPLICIT_IMPLEMENTATION
在我的项目中发出警告,当协议中的所需方法也需要由所有子类实现时。
这是协议 -
NS_PROTOCOL_REQUIRES_EXPLICIT_IMPLEMENTATION
@protocol ExplicitProtocol <NSObject>
@required
- (void)requiredMethod1;
- (void)requiredMethod2;
@optional
- (void)optionalMethod1;
- (void)optionalMethod2;
@end
基类标题 -
@interface BaseClass : NSObject<ExplicitProtocol>
@end
基类实施 -
@implementation BaseClass
-(void)requiredMethod1
{
}
-(void)requiredMethod2
{
}
@end
SubClass标题
@interface SubClass : BaseClass
@end
子类实现
@implementation SubClass
//No protocol methods implemented here
@end
由于SubClass
中未实现requiredMethods,我希望抛出警告。
有没有办法在Objective C中实现这一目标?我在这里做错了什么?