In writing the code when the gap is actually not to look out, many times it does not matter what is called, many people in order to facilitate understanding, simply called function calls.
This should actually be a feature of OC, message sent.
The specific class
typedef struct objc_class *Class; typedef struct objc_object { Class isa; } *id; typedef struct objc_selector *SEL; typedef id (*IMP)(id, SEL, ...);
Class structure
struct objc_class {
**struct** objc_class
**super_class; /*父类*/**
const char *name; **/***类名字*/
long version; ** /***版本信息*/
long info; **/***类信息*/
long instance_size; **/***实例大小*/
**struct** objc_ivar_list *ivars; ** /***实例参数链表*/
**struct** objc_method_list **methodLists; ** /*方法链表*/**
**struct** objc_cache *cache; **/***方法缓存*/
**struct** objc_protocol_list *protocols; ** /*协议链表*/**
};
In this methodlists is a list of methods
typedef struct objc_method *Method;
typedef struct objc_ method {
**SEL method_name;//方法名称**
**char *method_types;//方法参数类型**
**IMP method_imp;//方法实现的函数指针**
};
When you send a message, first go back to its corresponding method list, find it will use the corresponding method.
This is roughly the process, and of course there are a lot of details.
1, it first finds the SEL corresponding method to implement IMP. Because different classes may have different implementations for the same method, the method implementations found depend on the type of the message receiver.
2, then pass the message receiver object (pointer to the message receiver object) and the parameters specified in the method to the method implementation IMP.
3, finally, the return value of the method implementation is returned as the return value of the function. Starain Dou Bean/natewang (Jane book author)
Original link: http://www.jianshu.com/p/ca70bfb142da
Copyright belongs to the author, please contact the author to obtain authorization, and Mark "book author".
function call and send message to object (runtime Understanding)