先看一下官方文檔的說法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