respondsToSelector和conformsToProtocol

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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 转至元数据结尾创建: 董潇伟,最新修改于: 十二月 23, 2016 转至元数据起始第一章:isa和Class一....
    40c0490e5268阅读 1,758评论 0 9
  • 本文详细整理了 Cocoa 的 Runtime 系统的知识,它使得 Objective-C 如虎添翼,具备了灵活的...
    lylaut阅读 822评论 0 4
  • 我们常常会听说 Objective-C 是一门动态语言,那么这个「动态」表现在哪呢?我想最主要的表现就是 Obje...
    Ethan_Struggle阅读 2,230评论 0 7
  • 参考链接: http://www.cnblogs.com/ioshe/p/5489086.html 简介 Runt...
    乐乐的简书阅读 2,153评论 0 9
  • Objective-C语言是一门动态语言,它将很多静态语言在编译和链接时期做的事放到了运行时来处理。这种动态语言的...
    有一种再见叫青春阅读 606评论 0 3