对应.h文件
#import<Foundation/Foundation.h>
@protocol testProtocol
- (void)A;
@end
@interfacetestonformsToProtocol :NSObject<testProtocol>
@end
@interfacetestonformsToProtocolChindren :testonformsToProtocol
@end
对应.m文件
#import "testonformsToProtocol.h"
@implementation testonformsToProtocol
@end
@implementation testonformsToProtocolChindren
@end
对应main函数
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)];
输出结果:
isResponseToFather:NO,isConformToFather:YES
isResponseToChildren:NO,isConformToChildren:YES
所以似乎conformsToProtocol只与<testProtocol>有关
修改对应.m文件为:
@implementation testonformsToProtocol
- (void)A{};
@end
@implementation testonformsToProtocolChindren
@end
输出结果:
isResponseToFather:YES,isConformToFather:YES
isResponseToChildren:YES,isConformToChildren:YES