June 2016
Intermediate to advanced
214 pages
5h 40m
English
Key Value Observing (KVO) is the sister API to KVC. KVO allows us to request notifications when an attribute has changed. By observing attributes on an object, we can react when those attributes are changed. KVO is also implemented via an informal protocol on the NSObject, and we register and remove observers using addObserver(: forKeyPath: options: context:) and removeObserver(: forKeyPath:). These are the two primary methods, although there are other methods involved in the protocol, just as with KVC. If we wanted to observe the name value on a recipe, we’d add ourselves (or another object) as an observer for that value, like so:
| | let kPragProgObserver = "PragProgObserver" |
| | let myRecipe = ... |
| | myRecipe.addObserver( ... |
Read now
Unlock full access