oc的运行时系统

Objective-C is a class-based object system. Each object is an instance of some class; the object's isa pointer points to its class. That class describes the object's data: allocation size and ivar types and layout. The class also describes the object's behavior: the selectors it responds to and instance methods it implements.

 

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

 

 

一、运行时结构系统

typedef struct objc_class *Class;

typedef struct objc_object *id;

 

struct objc_class {

    Class isa  OBJC_ISA_AVAILABILITY;

}

 

struct objc_object {

    Class isa  OBJC_ISA_AVAILABILITY;

};

 

1、Class本身是一个类型结构,定义了类类型的组成和存储形式;

 

2、oc的类信息在编译时被编译为class的实例;即将oc的类信息保存在一个Class实例的结构中。

struct objc_class {

    Class isa  OBJC_ISA_AVAILABILITY;

    #if !__OBJC2__

    Class super_class                                        OBJC2_UNAVAILABLE;

    const char *name                                         OBJC2_UNAVAILABLE;

    long version                                             OBJC2_UNAVAILABLE;

    long info                                                OBJC2_UNAVAILABLE;

    long instance_size                                       OBJC2_UNAVAILABLE;

    struct objc_ivar_list *ivars                             OBJC2_UNAVAILABLE;

    struct objc_method_list **methodLists                    OBJC2_UNAVAILABLE;

    struct objc_cache *cache                                 OBJC2_UNAVAILABLE;

    struct objc_protocol_list *protocols                     OBJC2_UNAVAILABLE;

    #endif

} OBJC2_UNAVAILABLE;

 

3、oc的对象在创建时,会与它的类型信息进行关联。

isa;

 

二、运行时构建系统

isa

method

 

三、运行时执行(解释)系统

 

1、查找执行系统

_objc_msgSend

objc_msgSendSuper

the superclass at which to start searching for the method implementation

 

2、解释转发系统

_objc_msgForward

 

ForwardInvocation

 

3、

 

posted @ 2019-10-15 15:12  zzfx  阅读(223)  评论(0编辑  收藏  举报