改定履历:
2012-05-07---------------新建文本文档
正文:
本文原文地址
Class Introspection
1. 确认objective-c对象是否是一个类的实例:[obj isMemberOfClass:someClass];
2. 确认objective-c对象是否是一个类的实例或是其子孙.
[obj isKindOfClass:someClass];
3. 类版本:
[MyString version]
4. 找出objective-c对象的类
Class c = [obj1 class];
Class c = [NSString class];
5. 验证两个objective-c对象是否属于同一个类:
[obj1 class] == [obj2 class]
Objective-C Selector
objective-c 选择器(selector)是objective-c对象方法的唯一标识.1. 获取方法的selector:
SEL mySelector;
mySelector = @selector(setValue:param2:);
2. 从字符串获取selector
mySelector = NSSelectorFromString(name);
3. 以字符串的方式返回方法名:
NSString method = NSStringFromSelector(mySelector);
在运行时验证一个对象实现了哪些内容:
确认对象是否实现了某方法:if ( [myObj respondsToSelector:@selector(method1:)] ) {
[myObj method1];
}
运行时方法调用:
运行时使用"selector"运行方法:
[obj performSelector:@selector(method1:)
withObject:value];
等价于:
[obj method1:value];
===============================本系列教程结束===========================