The full name of KVO is Key-value observing, which implements a mechanism for adding observers to the object of interest, which is notified when the value of the attribute changes, and we can handle the change accordingly. Students who have seen design patterns should know that this is a typical observer pattern. The biggest advantage of KVO is that the underlying framework has been supported, and developers do not need to implement a scheme to send notifications when property values change, thus greatly reducing the amount of development effort. Second, the KVO framework is powerful, enabling multiple observers to observe the same attribute, or an observer to listen for different properties.
The use of KVO is relatively simple, basically three steps:
1. Registered Observer
AddObserver:forKeyPath:options:context:
2. The Observer realizes
ObserveValueForKeyPath:ofObject:change:context:
3. Remove the viewer (when the view exits)
Removeobserver:forkeypath:
Easy use of IOS Watcher mode (KVO)