36 Key-Value Observing

Key-value observing is a technique that lets you get a notification when a particular property of an object changes. Although you will not use it everyday, key-value observing (or KVO) is a crucial part of what makes Cocoa bindings and Core Data possible.

Essentially, you tell an object, I want to watch your fido property. If it changes, let me know. When the setFido: method gets called, you will get sent a message from the object you are observing: Hey, my fido property has a new value.

When you add yourself as an object’s observer, you specify the name of the property you are observing. You can also specify some options. In particular, you can tell the object to send you the old and/or new value of ...

Get Objective-C Programming: The Big Nerd Ranch Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.