isa class superclass metaclass

Posted feng9exe

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了isa class superclass metaclass相关的知识,希望对你有一定的参考价值。

 

 

技术图片

 http://www.cnblogs.com/feng9exe/p/7232915.html

 

Note: 其实这里的难点就在于对 和 的区分。

  • .class 当 target 是 Instance 则返回 Class,当 target 是 Class 则返回自身
  • object_getClass 返回 指针的指向 

 

ViewController: 0x10deee650, ViewController, 0

ViewController: 0x10deee678, NSObject, 1

NSObject: 0x10ef8cee8, NSObject, 1

NSObject: 0x10ef8cee8, NSObject, 1

 

ViewController

UIViewController

UIResponder

NSObject

 

ViewController: 0x10deee650, ViewController, 0

ViewController: 0x10deee650, ViewController, 0

 

 

   Class currentClass = object_getClass(self);

    Class nextClass = object_getClass(currentClass);

    Class superClass = class_getSuperclass(currentClass);

    Class xClass = self.class;

 

    int k = 0;

    do {

        NSLog(@"%@: %p, %s, %zd",NSStringFromClass(currentClass),currentClass,object_getClassName(currentClass),class_isMetaClass(currentClass));

        currentClass = nextClass;

        nextClass = object_getClass(currentClass);

    }while (k++ < 4);

    

    NSLog(NSStringFromClass(self.class));

    while (superClass != NULL) {

        NSLog(NSStringFromClass(superClass));

        superClass = class_getSuperclass(superClass);

    }

    

    k = 0;

    do {

        NSLog(@"%@: %p, %s, %zd",NSStringFromClass(xClass),xClass,object_getClassName(xClass),class_isMetaClass(xClass));

        xClass = xClass.class;

        //nextClass = object_getClass(currentClass);

    }while (k++ < 3);

 

以上是关于isa class superclass metaclass的主要内容,如果未能解决你的问题,请参考以下文章

iOS开发面试只需知道这些,技术基本通关!(Runtime篇)

OC 类的结构分析

iOS方法缓存-cache

isKindOfClass和isMemberOfClass

OC原理-isa详解

NSObjectClass objc_class objc_objct isa_t