isKindOfClass和isMemberOfClass之间的区别是:


1.isKindOfClass是判断对象是否是一个类的实例,或者是该类祖先类的实例;
2.isMemberOfClass只能用来判断前者,不能用来判断后者

@interface SuperClass : NSObject
@end
@interface ChildClass : SuperClass
@end
SuperClass *superOb = [[SuperClass alloc]init];
ChildClass * childOb = [[ChildClass alloc]init];

[superOb isKindOfClass:[SuperClass Class]]; // YES
[superOb isKindOfClass:[ChildClass Class]]; // NO

[childOb isKindOfClass:[SuperClass Class]]; // YES
[childOb isKindOfClass:[ChildClass Class]]; // YES

[superOb isMemberOfClass:[SuperClass Class]]; // YES
[superOb isMemberOfClass:[ChildClass Class]]; // NO

[childOb isMemberOfClass:[SuperClass Class]]; // NO
[childOb isMemberOfClass:[ChildClass Class]]; // YES

你可能感兴趣的:(isKindOfClass和isMemberOfClass之间的区别是:)