在类别中添加not respond selector
的处理
注意点:
- 交换方法在
+ (void)load
中添加 ,实例方法class_getInstanceMethod
,类方法class_getClassMethod
,交换用method_exchangeImplementations
,也可以用method_setImplementation
2.在类别中添加重写load
会调用所有类别中的load
方法
3.not respond
时会先调用 +resolveInstanceMethod:
,可以在这里class_addMethod
处理
4.若+resolveInstanceMethod:
返回NO
,则会继续调用forwardingTargetForSelector
,此时可以返回一个respond sel
的obj
作为消息对象,即 更换消息接收者;
5.1 若 forwardingTargetForSelector
返回nil
,则会继续调用-methodSignatureForSelector:
,
5.2 这时可以返回了一个函数签名,然后Runtime
就会创建一个NSInvocation
对象并发送-forwardInvocation:
消息给目标对象
5.3 此时我们可以在-forwardInvocation:
中 调用 NSInvocation invokeWithTarget:(可响应的对象)
网友评论