使用-conformsToProtocol:函数,具体用法如下:
@protocol MyProtocol <NSObject>
@required
- (void)onUpdate;
@end
@interface ProtocolTest : NSObject<MyProtocol>
- (void)onUpdate;
@end
@interface ProtocolTestChildClass : ProtocolTest
@end
调用:
ProtocolTestChildClass *protocolChild = [[ProtocolTestChildClass alloc] init];
BOOL hasProtocol = [protocolChild conformsToProtocol:@protocol(MyProtocol)];
CCLOG(@"has protocol = %d", hasProtocol);
结果:
has protocol = 1