對(duì)應(yīng).h文件
#import<Foundation/Foundation.h>
@protocol testProtocol
- (void)A;
@end
@interfacetestonformsToProtocol :NSObject<testProtocol>
@end
@interfacetestonformsToProtocolChindren :testonformsToProtocol
@end
對(duì)應(yīng).m文件
#import "testonformsToProtocol.h"
@implementation testonformsToProtocol
@end
@implementation testonformsToProtocolChindren
@end
對(duì)應(yīng)main函數(shù)
testonformsToProtocol *classFather = [[testonformsToProtocol alloc] init];
testonformsToProtocolChindren *classChildern = [[testonformsToProtocolChindren alloc] init];
BOOL isResponseToFather = [classFather respondsToSelector:@selector(A)];
BOOL isConformToFather = [classFather conformsToProtocol:@protocol(testProtocol)];
BOOL isResponseToChildren = [classChildern respondsToSelector:@selector(A)];
BOOL isConformToChildren = [classChildern conformsToProtocol:@protocol(testProtocol)];
輸出結(jié)果:
isResponseToFather:NO,isConformToFather:YES
isResponseToChildren:NO,isConformToChildren:YES
所以似乎conformsToProtocol只與<testProtocol>有關(guān)
修改對(duì)應(yīng).m文件為:
@implementation testonformsToProtocol
- (void)A{};
@end
@implementation testonformsToProtocolChindren
@end
輸出結(jié)果:
isResponseToFather:YES,isConformToFather:YES
isResponseToChildren:YES,isConformToChildren:YES