动态类型检测来判断对象的所属关系:
Animal *ani = [Animal new];
Dog *dog = [Dog new];
BigYellowDog *byd = [BigYellowDog new];
1)判断对象是否为类或者子类的实例变量
BOOL isYes = [dog isKindOfClass:[Animal class]];
NSLog(@"isYes = %d",isYes);
//返回的是YES
2)判断对象是否是类的实例变量
isYes = [dog isMemberOfClass:[dog class]];
NSLog(@"isYes = %d",isYes);
//返回的是YES
3)判断一个类是否为另一个类的子类
isYes = [Dog isSubclassOfClass:[Animal class]];
NSLog(@"isYes = %d",isYes);
//返回的是YES
|
|