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