Parameters from observeValueForKeyPath:ofObject:change:context: Parameters from observeValueForKeyPath:ofObject:change:context: objective-c objective-c

Parameters from observeValueForKeyPath:ofObject:change:context:


When you registered for KVO notifications you specified a keypath to addObserver:. The keypath parameter is simply this value being returned to you. The object parameter is the object to which you sent the addObserver: message. These can be used to differentiate between KVO notifications of different keypaths/objects (for instance if you're observing multiple values).

change is a dictionary that contains information about the nature of the value change. It might contain the new value or the old value or, for to-many relationships, it might contain the indices that changed. Its contents are better described in the KVO Programming Guide in the Receiving Notification of a Change section.

When you register for the notification you can also specify a context value. The last value is simply this value returned to you. If you don't have any context-specific information, passing nil to addObserver: is appropriate.

For a good discussion on some shortcomings of the KVO system (and some helper classes to address them), see Mike Ash's great blog post