大部分的动态反射支持来自NSObject 类。NSObject是所有类(除了一些很少见的例外)的根类。所以所有你写的类应该都可以支持反射
NSObject 提供了一些简单的查询运行时系统信息的方法:
- (BOOL)isKindOfClass:(Class)aClass 判断是否是指定类或其子类的实例(检查继承关系)
Returns a Boolean value that indicates whether the receiver is an instance of given class or an instance of any class that inherits from that class.
- (BOOL)isMemberOfClass:(Class)aClass 判断是否是指定类的实例(精确类匹配)
Returns a Boolean value that indicates whether the receiver is an instance of a given class.
- (BOOL)respondsToSelector:(SEL)aSelector 是否实现或继承了指定方法
Returns a Boolean value that indicates whether the receiver implements or inherits a method that can respond to a specified message.
- (BOOL)conformsToProtocol:(Protocol *)aProtocol 是否符合协议
Returns a Boolean value that indicates whether the receiver conforms to a given protocol.