美文网首页
respondsToSelector和conformsToPro

respondsToSelector和conformsToPro

作者: qbb_kbb | 来源:发表于2016-06-08 16:18 被阅读0次

对应.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

相关文章

网友评论

      本文标题:respondsToSelector和conformsToPro

      本文链接:https://www.haomeiwen.com/subject/pyyjdttx.html