一、類的數(shù)據(jù)結(jié)構(gòu)
Class(指針)
typedef struct objc_class *Class;
/*
這是由編譯器為每個(gè)類產(chǎn)生的數(shù)據(jù)結(jié)構(gòu),這個(gè)結(jié)構(gòu)定義了一個(gè)類.這個(gè)結(jié)構(gòu)是通過編譯器在執(zhí)行時(shí)產(chǎn)生,在運(yùn)行時(shí)發(fā)送消息時(shí)使用.因此,一些成員改變了類型.編譯器產(chǎn)生"char* const"類型的字符串指針替代了下面的成員變量"super_class"
*/
struct objc_class {
struct objc_class* class_pointer; /* 指向元類的指針. */
struct objc_class* super_class; /* 指向父類的指針. 對于NSObject來說是NULL.*/
const char* name; /* 類的名稱. */
long version; /* 未知. */
unsigned long info; /* 比特蒙板. 參考下面類的蒙板定義. */
long instance_size; /* 類的字節(jié)數(shù).包含類的定義和所有父類的定義 */
#ifdef _WIN64
long pad;
#endif
struct objc_ivar_list* ivars; /* 指向類中定義的實(shí)例變量的列表結(jié)構(gòu). NULL代表沒有實(shí)例變量.不包括父類的變量. */
struct objc_method_list* methods; /* 鏈接類中定義的實(shí)例方法. */
struct sarray * dtable; /* 指向?qū)嵗椒ǚ峙浔? */
struct objc_class* subclass_list; /* 父類列表 */
struct objc_class* sibling_class;
struct objc_protocol_list *protocols; /* 要實(shí)現(xiàn)的原型列表 */
void* gc_object_type;
};
Method(指針)
typedef struct objc_method *Method;
/* 編譯器依據(jù)類中定義的方法為該類產(chǎn)生一個(gè)或更多這種這種結(jié)構(gòu).
一個(gè)類的實(shí)現(xiàn)可以分散在一個(gè)文件中不同部分,同時(shí)類別可以分散在不同的模塊中.為了處理這個(gè)問題,使用一個(gè)單獨(dú)的方法鏈表 */
struct objc_method
{
SEL method_name; /* 這個(gè)變量就是方法的名稱.編譯器使用在這里使用一個(gè)`char*`,當(dāng)一個(gè)方法被注冊,名稱在運(yùn)行時(shí)被使用真正的SEL替代 */
const char* method_types; /* 描述方法的參數(shù)列表. 在運(yùn)行時(shí)注冊選擇器時(shí)使用.那時(shí)候方法名就會包含方法的參數(shù)列表.*/
IMP method_imp; /* 方法執(zhí)行時(shí)候的地址. */
};```
## Ivar(指針)
```objc
typedef struct objc_ivar *Ivar;
/* 編譯器依據(jù)類中定義的實(shí)例變量為該類產(chǎn)生一個(gè)或更多這種這種結(jié)構(gòu) */
struct objc_ivar
{
const char* ivar_name; /* 類中定義的變量名. */
const char* ivar_type; /* 描述變量的類型.調(diào)試時(shí)非常有用. */
int ivar_offset; /* 實(shí)例結(jié)構(gòu)的基地址偏移字節(jié) */
};```
##Category(指針)
```objc
typedef struct objc_category *Category;
/* 編譯器為每個(gè)類別產(chǎn)生一個(gè)這樣的結(jié)構(gòu).一個(gè)類可以具有多個(gè)類別同時(shí)既包括實(shí)例方法,也可以包括類方法*/
struct objc_category
{
const char* category_name; /* 類別名.定義在類別后面的括號內(nèi)*/
const char* class_name; /* 類名 */
struct objc_method_list *instance_methods; /* 鏈接類中定義的實(shí)例方法. NULL表示沒有實(shí)例方法. */
struct objc_method_list *class_methods; /* 鏈接類中定義的類方法. NULL表示沒有類方法. */
struct objc_protocol_list *protocols; /* 遵循的協(xié)議表 */
};
objc_property_t
typedef struct objc_property *objc_property_t;
IMP
id (*IMP)(id, SEL, ...)
SEL
typedef struct objc_selector *SEL;
struct objc_selector
{
void *sel_id;
const char *sel_types;
};
objc_method_list
struct objc_method_list
{
struct objc_method_list* method_next; /* 這個(gè)變量用來鏈接另一個(gè)單獨(dú)的方法鏈表 */
int method_count; /* 結(jié)構(gòu)中定義的方法數(shù)量 */
struct objc_method method_list[1]; /* 可變長度的結(jié)構(gòu) */
};
objc_cache
struct objc_cache
{
unsigned int mask;
unsigned int occupied;
Method buckets[1];
};
objc_protocol_list
struct objc_protocol_list
{
struct objc_protocol_list *next;
size_t count;
struct objc_protocol *list[1];
};
二抡柿、實(shí)例的數(shù)據(jù)結(jié)構(gòu)
id
typedef struct objc_object *id;```
## objc_object
```objc
struct objc_object
{
// 類的指針是對象相關(guān)的類.如果是一個(gè)類對象, 這個(gè)指針指向元類.
Class isa;
};```
## objc_super
```objc
struct objc_super
{
id self; /* 消息的接受者 */
Class super_class; /* 接受者的父類 */
};
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者