class
- 实例对象: 返回对象的isa 即类对象
- 类对象,元类,根元类:返回自己 self
object_getClass
- 返回对象的isa
static inline void classLog(id obj){
Class cls1 = [obj class];
Class cls2 = object_getClass(obj);
NSLog(@"==============================================================");
NSLog(@"对象: %@ %p 是否是元类:%@",obj,obj,class_isMetaClass(obj) ? @"是":@"否");
NSLog(@"class方法: %@ %p 是否是元类:%@",cls1,cls1,class_isMetaClass(cls1) ? @"是":@"否");
NSLog(@"object_getClass方法: %@ %p 是否是元类:%@",cls2,cls2,class_isMetaClass(cls2) ? @"是":@"否");
NSLog(@"两个实例是否相等: %@",[cls1 isEqual:cls2] ? @"是":@"否");
NSLog(@"==============================================================");
}
- (void)testClass{
Person *person = [Person new];
classLog(person);
Class personClass = object_getClass(person);
classLog(personClass);
Class personMetaClass = object_getClass(personClass);
classLog(personMetaClass);
Class nsobjectMetaClass = object_getClass(personMetaClass);
classLog(nsobjectMetaClass);
}