先看一下官方文档的说法bash
isKindOfClass: 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.
//调用者是给定类的实例或者是给定类的子类的实例
isMemberOfClass: Returns a Boolean value that indicates
whether the receiver is an instance of a given class.
//调用者是不是给定类的实例
复制代码
而后看一道题目:spa
BOOL res1 = [(id)[NSObject class] isKindOfClass:[NSObject class]];
BOOL res2 = [(id)[NSObject class] isMemberOfClass:[NSObject class]];
BOOL res3 = [(id)[xxObj class] isKindOfClass:[xxObj class]];
BOOL res4 = [(id)[xxObj class] isMemberOfClass:[xxObj class]];
复制代码
答案是:YES / NO / NO / NOcode
协议有一套类方法的隐藏实现,因此编译运行正常; 因为NSObject meta class的父类为NSObject class,因此只有第一句为YES 看一下图就明白了: cdn