iOS difference between isKindOfClass and isMemberOfClass

后端 未结 6 724
礼貌的吻别
礼貌的吻别 2020-11-28 01:37

What is the difference between the isKindOfClass:(Class)aClass and the isMemberOfClass:(Class)aClass functions? I know it is something small like,

6条回答
  •  余生分开走
    2020-11-28 02:15

    Because of class clusters, isMemberOfClass can give you an answer you might not expect. In many cases your best choice is more likely to be -(BOOL)conformsToProtocol:(SEL)aSelector or - (BOOL)conformsToProtocol:(Protocol*)aProtocol. I.e, it's better to test these if they can answer your need rather than testing class/subclass.

    See apple doc for NSObject class and protocol:

    http://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSObject_Class/Reference/Reference.html#//apple_ref/occ/cl/NSObject

    http://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Protocols/NSObject_Protocol/Reference/NSObject.html#//apple_ref/occ/intf/NSObject

提交回复
热议问题