O'Reilly logo

Objective-C Memory Management Essentials by Gibson Tang, Maxim Vasilkov

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

Key-value observing

Key-value observing—also known as KVO—is a way to get notified about changes in a variable, but only if it was changed using KVC. We can highlight two things out of this:

  • Firstly, you need KVC in order to do KVO
  • Secondly, if a variable is changed directly without key-value coding by its default setter and getter methods, you won't get notified at all

Every variable in any key path can be observed by an object. It's useful if you consider using KVO. As KVO is built on top of KVC, you need KVC to implement KVO, and using KVO should be one of the reasons why you need to use KVC.

Implementing key-value observing

It is relatively easy to implement KVO, as we shall see in the following code example. On the specified key path, you add ...

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