O'Reilly logo

Core Data iOS Essentials by B.M. Harwani

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using KVO to know what has been updated

Key Value Observing (KVO) is the sister API to KVC and is used to inform us if a particular attribute of an object is changed. Consequently, we can take necessary action on getting notification of the change(s) that took place on any attribute of the object. To get the notification, we have to register our controller class (referred to as self) as an observer of the object for the keypath, where keypath is the name of the attribute of the object that we want to observe.

To register the observer, we use -addObserver:forKeyPath:options:context: method and to remove the observers, we use -removeObserver: forKeyPath: method.

Let us have a look at the syntax of the method that registers an observer:

[object addObserver:self ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required