objc_object算法
objc_class緩存
cache_tbash
class_data_bits_t數據結構
isa 指針函數
實例對象,isa指向其類對象ui
類對象,isa指向其元類對象spa
method_t 指針
Type Encodingscode
整體 cdn
super
void objc_msgSend(void /* id self, SEL op, ... */)
// [self class] => objc_msgSend(self, @selector(class))
複製代碼
void objc_msgSendSuper(void /* struct objc_super *super, SEL op, ... */)
struct objc_super {
/// Specifies an instance of a class
__unsafe_unretained id receiver;
};
// [super class] => objc_msgSendSuper(super, @selector(class))
複製代碼
緩存查找
給定值是SEL,目標值是對應的bucket_t中的IMP
當前類中查找
父類逐級查找
消息轉發
+ (BOOL)resolveInstanceMethod:(SEL)sel {
if (sel == @selector(test)) {
// 動態添加test方法的實現
class_addMethod(self, @selector(test), testImp, "v@:");
return YES;
} else {
// 返回父類的默認調用
return [super resolveInstanceMethod:sel];
}
}
複製代碼
@dynamic