NSKeyValueObserving
An informal protocol that objects adopt to be notified of changes to the specified properties of other objects.
Overview
You can observe any object properties including simple attributes, to-one relationships, and to-many relationships. Observers of to-many relationships are informed of the type of change made — as well as which objects are involved in the change.
NSObject provides an implementation of the NSKeyValueObserving protocol that provides an automatic observing capability for all objects. You can further refine notifications by disabling automatic observer notifications and implementing manual notifications using the methods in this protocol.
Topics
Change Notification
Registering for Observation
addObserver(_:forKeyPath:options:context:)removeObserver(_:forKeyPath:)removeObserver(_:forKeyPath:context:)
Notifying Observers of Changes
willChangeValue(forKey:)didChangeValue(forKey:)willChange(_:valuesAt:forKey:)didChange(_:valuesAt:forKey:)willChangeValue(forKey:withSetMutation:using:)didChangeValue(forKey:withSetMutation:using:)
Observing Customization
automaticallyNotifiesObservers(forKey:)keyPathsForValuesAffectingValue(forKey:)NSKeyValueObservingCustomizationobservationInfo
Constants
See Also
Related Documentation
- Key-Value Observing Programming Guide