Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

说一下 Runtime 消息转发。 #54

Open
tbfungeek opened this issue Feb 7, 2020 · 0 comments
Open

说一下 Runtime 消息转发。 #54

tbfungeek opened this issue Feb 7, 2020 · 0 comments

Comments

@tbfungeek
Copy link
Owner

forwardflow

这里将消息决议和消息转发合在一起。

  • 在消息解析失败的情况下会经过消息决议,在这个步骤可以动态添加方法,方法决议之后还会进行一轮消息解析。
  • 消息决议失败后会走 -(id)forwardingTargetForSelector:(SEL)aSelector这个方法会根据传入的selector,返回一个备用的target,这个消息会被转发给它进行处理,
    如果 -(id)forwardingTargetForSelector:(SEL)aSelector 返回nil 或者self,就会进入下一步。运行时系统首先会调用 -(NSMethodSignature )methodSignatureForSelector:(SEL)aSelector方法来获得记录了方法的参数和返回值的信息的方法签名。如果methodSignatureForSelector 返回的是nil, 运行时系统会抛出unrecognized selector exception ,程序到这里就结束了否则会继续调用 -(void)forwardInvocation:(NSInvocation)anInvocation 这个方法就十分灵活了,可以更改参数甚至SEL,可以发给任何对象target。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant