11 explains the message passing mechanism of the object
12 What happens when a message is received that cannot be read will start the message forwarding mechanism,
- If the object cannot respond to a selector, it enters the message forwarding process.
- 1, through the dynamic method of the runtime analysis function, you can use a method when you need to add it to the class.
- 2, an object can transfer certain selectors that it cannot interpret to other objects for processing.
- After these two steps, if there is still no way to handle the selection, then start the complete message forwarding mechanism.
Dynamic Method Parsing
After the object receives a message that cannot be read, the following class methods of the class to which it belongs are called first
+ (BOOL) Resolveinstancemethod: (SEL) Selector
The return value is bool, indicating whether the class can add an instance method to handle this selector.
The premise of using this method is: the implementation code of the relevant method has been written well, just waiting for the runtime to plug in the dynamic in the class. This scenario is commonly used to implement @dynamic properties, such as the ability to access properties of Nsmanagedobjects objects in the CoreData framework, because the access methods required to implement these properties can be determined at compile time.
The following code shows how to use "Resolveinstancemethod:" to achieve @dynamic implementation;
Effective OBJECTIVE-C 2.0-12th: Understanding the message forwarding mechanism