O'Reilly logo

Cocoa Programming for OS X: The Big Nerd Ranch Guide by Aaron Hillegass, Adam Preble, Nate Chandler

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 the Context Pointer Defensively

In order for any class to observe key-value changes, it must implement the observeValueForKeyPath(_:ofObject:change:context:) method; it is not possible to provide a different method to KVO. Consequently, it is possible to mistakenly intercept notifications intended for a superclass.

Consider the case of some class Maple, which is a subclass of some other class Tree. Both classes observe Environment’s key path season independently. Unless the developer takes precautions, Maple will receive its key-value-observing messages and those intended for Tree, because Maple has effectively overridden Tree’s KVO method. To fix this, Maple must correctly distinguish between KVO notifications intended for it ...

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