源码
+ (BOOL)isMemberOfClass:(Class)cls {
return self->ISA() == cls;
}
- (BOOL)isMemberOfClass:(Class)cls {
return [self class] == cls;
}
+ (BOOL)isKindOfClass:(Class)cls {
for (Class tcls = self->ISA(); tcls; tcls = tcls->getSuperclass()) {
if (tcls == cls) return YES;
}
return NO;
}
- (BOOL)isKindOfClass:(Class)cls {
for (Class tcls = [self class]; tcls; tcls = tcls->getSuperclass()) {
if (tcls == cls) return YES;
}
return NO;
}
调用者是对象
isMemberOfClass只看当前对象的类是否和参数一致。
isKindOfClass会遍历当前对象的继承链,有相同的类返回YES。
调用者是类对象
isMemberOfClass只看当前类的元类是否和参数一致。
isKindOfClass会遍历当前类的元类的继承链,有相同的元类类返回YES。