Instance Method

removeObserver:forKeyPath:context:

Stops the observer object from receiving change notifications for the property specified by the key path relative to the object receiving this message, given the context.

Declaration

- (void)removeObserver:(NSObject *)observer forKeyPath:(NSString *)keyPath context:(void *)context;

Parameters

observer

The object to remove as an observer.

keyPath

A key-path, relative to the observed object, for which observer is registered to receive KVO change notifications.

context

Arbitrary data that more specifically identifies the observer to be removed.

Discussion

Examining the value in context you are able to determine precisely which addObserver:forKeyPath:options:context: invocation was used to create the observation relationship. When the same observer is registered for the same key-path multiple times, but with different context pointers, an application can determine specifically which object to stop observing. It is an error to call removeObserver:forKeyPath:context: if the object has not been registered as an observer.

Be sure to invoke this method (or removeObserver:forKeyPath:) before any object specified in addObserver:forKeyPath:options:context: is deallocated.

See Also

Registering for Observation

- addObserver:forKeyPath:options:context:

Registers the observer object to receive KVO notifications for the key path relative to the object receiving this message.

- removeObserver:forKeyPath:

Stops the observer object from receiving change notifications for the property specified by the key path relative to the object receiving this message.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software