美文网首页
not respond selector 的处理

not respond selector 的处理

作者: jay_丶 | 来源:发表于2019-07-10 16:29 被阅读0次

    在类别中添加not respond selector 的处理

    注意点:

    1. 交换方法在 + (void)load 中添加 ,实例方法class_getInstanceMethod,类方法class_getClassMethod,交换用method_exchangeImplementations,也可以用 method_setImplementation

    2.在类别中添加重写load 会调用所有类别中的load方法

    3.not respond时会先调用 +resolveInstanceMethod: ,可以在这里class_addMethod 处理

    4.若+resolveInstanceMethod: 返回NO,则会继续调用forwardingTargetForSelector,此时可以返回一个respond selobj作为消息对象,即 更换消息接收者;

    5.1 若 forwardingTargetForSelector 返回nil,则会继续调用-methodSignatureForSelector:

    5.2 这时可以返回了一个函数签名,然后Runtime就会创建一个NSInvocation对象并发送-forwardInvocation:消息给目标对象

    5.3 此时我们可以在-forwardInvocation:中 调用 NSInvocation invokeWithTarget:(可响应的对象)

    相关文章

      网友评论

          本文标题:not respond selector 的处理

          本文链接:https://www.haomeiwen.com/subject/wughkctx.html