When using KVO in a category implementation, it is recommended that a custom associated-object be used as an observer, rather than the object observing itself.
KVO generally monitors certain attribute changes of an OBJ_A and provides callbacks if expected changes occur.
Observing it yourself is theoretically OK (I haven't tried it...), because to put it bluntly, KVO is to observe the SETTER method of a certain attribute, but the readability of the code written this way is poor. The method everyone adopts is to write a separate associated object. .
The advantages of writing alone are:
Highly readable, don’t worry about observing yourself
Decoupling
It is convenient for business expansion, because the associated object is your custom object after all (it can be very abstract)
BLABLA
KVO, the interface provided by Apple, is too fucked up. It was designed with a very good idea. . . If you want to use KVO, I recommend Facebook’s KVOController
My personal feeling is that in order to keep the category simple, writing categories is generally relatively basic, but when you add KVO, you embed the business logic, which makes the possibility of this code being reused in the future
KVO generally monitors certain attribute changes of an OBJ_A and provides callbacks if expected changes occur.
Observing it yourself is theoretically OK (I haven't tried it...), because to put it bluntly, KVO is to observe the SETTER method of a certain attribute, but the readability of the code written this way is poor. The method everyone adopts is to write a separate associated object. .
The advantages of writing alone are:
BLABLA
KVO, the interface provided by Apple, is too fucked up. It was designed with a very good idea. . . If you want to use KVO, I recommend Facebook’s KVOController
My personal feeling is that in order to keep the category simple, writing categories is generally relatively basic, but when you add KVO, you embed the business logic, which makes the possibility of this code being reused in the future