class

    • 实例对象: 返回对象的isa 即类对象
    • 类对象,元类,根元类:返回自己 self

    object_getClass

    • 返回对象的isa
    1. static inline void classLog(id obj){
    2. Class cls1 = [obj class];
    3. Class cls2 = object_getClass(obj);
    4. NSLog(@"==============================================================");
    5. NSLog(@"对象: %@ %p 是否是元类:%@",obj,obj,class_isMetaClass(obj) ? @"是":@"否");
    6. NSLog(@"class方法: %@ %p 是否是元类:%@",cls1,cls1,class_isMetaClass(cls1) ? @"是":@"否");
    7. NSLog(@"object_getClass方法: %@ %p 是否是元类:%@",cls2,cls2,class_isMetaClass(cls2) ? @"是":@"否");
    8. NSLog(@"两个实例是否相等: %@",[cls1 isEqual:cls2] ? @"是":@"否");
    9. NSLog(@"==============================================================");
    10. }
    11. - (void)testClass{
    12. Person *person = [Person new];
    13. classLog(person);
    14. Class personClass = object_getClass(person);
    15. classLog(personClass);
    16. Class personMetaClass = object_getClass(personClass);
    17. classLog(personMetaClass);
    18. Class nsobjectMetaClass = object_getClass(personMetaClass);
    19. classLog(nsobjectMetaClass);
    20. }

    截屏2021-01-19 18.34.28.png