比較簡(jiǎn)單,只是記錄一下知識(shí)點(diǎn)。
一、 Class
1.網(wǎng)上扣了一張圖片:

image.png
Class 的一個(gè)結(jié)構(gòu)。
關(guān)于為什么&FAST_DATA_MASK是一種計(jì)算位域方法,取出對(duì)應(yīng)位域的值,具體可以看之前寫(xiě)的一篇探究 isa 本質(zhì)。
2.class_rw_t 真實(shí)定義:
class_rw_t:讀寫(xiě)、運(yùn)行時(shí)調(diào)用方法都是取之于此、類(lèi)的初始內(nèi)容、分類(lèi)的內(nèi)容。
struct class_rw_t {
// Be warned that Symbolication knows the layout of this structure.
uint32_t flags;
uint32_t version;
const class_ro_t *ro;
method_array_t methods;
property_array_t properties;
protocol_array_t protocols;
Class firstSubclass;
Class nextSiblingClass;
};
class method_array_t :
public list_array_tt<method_t, method_list_t>
{
typedef list_array_tt<method_t, method_list_t> Super;
public:
method_list_t **beginCategoryMethodLists() {
return beginLists();
}
method_list_t **endCategoryMethodLists(Class cls);
method_array_t duplicate() {
return Super::duplicate<method_array_t>();
}
};
method_array_t->method_list_t->method_t
3.class_ro_t 真實(shí)定義:
class_ro_t:只讀、包含的是類(lèi)的初始內(nèi)容。
struct class_ro_t {
uint32_t flags;
uint32_t instanceStart;
uint32_t instanceSize;
#ifdef __LP64__
uint32_t reserved;
#endif
const uint8_t * ivarLayout;
const char * name;
method_list_t * baseMethodList;
protocol_list_t * baseProtocols;
const ivar_list_t * ivars;
const uint8_t * weakIvarLayout;
property_list_t *baseProperties;
method_list_t *baseMethods() const {
return baseMethodList;
}
};
method_list_t -> method_t
4.method_t 真實(shí)定義:
struct method_t {
SEL name;
const char *types;
IMP imp;
};
SEL name:方法名字,方法選擇器
const char *types:方法類(lèi)型,字符串表示,方法編碼
IMP imp:函數(shù)指針,函數(shù)實(shí)現(xiàn)地址
5.Type Encoding
iOS中提供了一種@encode的指令,可以將具體類(lèi)型用字符串表示出來(lái)。


image.png
NSLog(@"%s",@encode(id));
2018-09-03 11:51:37.186767+0800 runtime[1030:38253] @