Introduction:
? Why do you want to write this? It's just a sudden thought. Let's talk about my current understanding.
KVC:
? Key-value coding is a mechanism that uses string identifiers to indirectly access object attributes. However, for this reason, I have never realized the benefits of using this feature for so long. I have no obvious reason to use setvalut: forkey instead of directly using an attribute. Of course, KVC is the basis for KVO implementation. What is the basis? Come down
KVO:
? KVO is actually an observer implementation. Two roles: Observer A and observer B. If B observes an attribute of a, B is notified when the attribute value of a changes. The basic principle is that, as long as the listening attribute of a changes, B's-(void) observevalueforkeypath :( nsstring *) keypath ofobject :( ID) object change :( nsdictionary *) will be called *) change context :( void *) context; To notify B.
There are two possibilities for this property change: one is to change the call property (call setter or KVC to find setter), and the other is to directly change the instance variable corresponding to the property through KVC. The latter is obviously not feasible, and there is no time to send notifications when changing. There is only one case, but to send a notification in the setter method, the native attribute does not implement this function, therefore, the system creates a derived class class_kvo_a corresponding to the class class_a when object A is listened on, and then overwrites the setter method of the monitored property, the rewritten setter can send notifications, and then points the ISA pointer of object A to class_kvo_a, in the future, when the observed attribute of a changes, the setter method of class_kvo_a will be called to change the value and send a notification to observer B. As for KVC, it is the basis of KVO. I personally think that KVO uses KVC to find the setter method through [setvalue: forkey]. If KVC is the basis of KVO, if there is no KVC, isn't it KVO? But this is obviously not the case. Without KVC, you just cannot change the attribute value in the way of [setvalue: forkey.
@ Mic
(Email: [email protected])
(Qq: 839720759)