码迷,mamicode.com
首页 > 其他好文 > 详细

instancesRespondToSelector与respondsToSelector的区别

时间:2014-08-26 11:06:05      阅读:214      评论:0      收藏:0      [点我收藏+]

标签:blog   http   os   io   ar   div   cti   代码   log   

Test1.h

bubuko.com,布布扣
@interface Test1 : NSObject

- (void)objectFun;

+ (void)classFun;

@end
bubuko.com,布布扣

 

Test1.m

bubuko.com,布布扣
@implementation Test1

- (void)objectFun
{
    NSLog(@"object function");
}

+ (void)classFun
{
    NSLog(@"class function");
}

@end
bubuko.com,布布扣

 

测试类:

bubuko.com,布布扣
BOOL flag;

flag = [Test1 instancesRespondToSelector:@selector(objectFun)]; //YES

flag = [Test1 instancesRespondToSelector:@selector(classFun)]; //NO

flag = [Test1 respondsToSelector:@selector(objectFun)]; //NO

flag = [Test1 respondsToSelector:@selector(classFun)]; //YES

Test1 *obj = [[Test1 alloc] init];

flag = [obj respondsToSelector:@selector(objectFun)]; //YES

flag = [obj respondsToSelector:@selector(classFun)]; //NO
bubuko.com,布布扣

 

总结:

1. instancesRespondToSelector只能写在类名后面,respondsToSelector可以写在类名和实例名后面。

2. [类 instancesRespondToSelector]判断的是该类的实例是否包含某方法,等效于:[该类的实例 respondsToSelector]。

3. [类 respondsToSelector]用于判断是否包含某个类方法。

instancesRespondToSelector与respondsToSelector的区别

标签:blog   http   os   io   ar   div   cti   代码   log   

原文地址:http://www.cnblogs.com/renhuanwei/p/3936535.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!