Rapid message forwarding process

Message forwarding, as the name implies, forwards messages to other recipients, that is, other objects

forwardingTargetForSelector

  • If we don’t do that eitherresolveInstanceMethodAfter viewing the log, you can see the call laterforwardingTargetForSelector
  • Take a look at the official documentation

If an object implements (or inherits) this method, and returns a non-nil (and non-self) result, that returned object is used as the new receiver object and the message dispatch resumes to that new object. (Obviously if you return self from this method, the code would just fall into an infinite loop.) If you implement this method in a non-root class, Invoking Super’s if your class has nothing to return for the given selector then you should return the result of invoking Super’s implementation. This method gives an object a chance to redirect an unknown message sent to it before the much more expensive forwardInvocation: machinery takes over. This is useful when you simply want to redirect messages to another object and can be an order of magnitude faster than regular forwarding. It is not useful where the goal of the forwarding is to capture the NSInvocation, or manipulate the arguments or return value during the forwarding.

  • It’s like redirecting
  • This can be called by returning a new objectmethod.
  • It’s consuming moreforwardInvocation:Methods before

  • WLWPersonDo not implementlookMethod, implementforwardingTargetForSelectorThe specifiedWLWTeachercalllook

The message is forwarded slowly

  • If not implemented alsoforwardingTargetForSelectorWill gomethodSigntureForSeletor
  • The official documentation

  • throughmethodSignatrueForSelectorTo get the signature of the message to create oneNSInvocationObject is used to forward messages
  • forwardingInvocationMethod to forward the message, of course, you can do no processing
  • The official demo

  • You can also calldoesNotRecognizeSelectorTo prevent message forwarding

The source code parsing

  • The print stack found that the message source came fromCFFoundation The source code
  • But find the source code does not find the corresponding code, may be no open source

  • If you want to continue exploring, you can go throughimage listFind the correspondingCoreFoundtionExecutable files, and then explore through disassembly
  • usingHopperTools will be foundCoreFoundtionDrag the executable file in