Protocol: NSKeyValueObserving
Overview
The NSKeyValueObserving (KVO) informal protocol defines a mechanism that allows objects to be notified of changes to the specified properties of other objects.Returns a Boolean value that indicates whether the receiver supports automatic key-value observation for the given key.Returns a set of key paths for properties whose values affect the value of the specified key.Registers anObserver to receive KVO notifications for the specified key-path relative to the receiver.Invoked to inform the receiver that the specified change has occurred on the indexes for a specified ordered to-many relationship.Invoked to inform the receiver that the value of a given property has changed.Invoked to inform the receiver that the specified change was made to a specified unordered to-many relationship.Returns a pointer that identifies information about all of the observers that are registered with the receiver.This message is sent to the receiver when the value at the specified key path relative to the given object has changed.Stops a given object from receiving change notifications for the property specified by a given key-path relative to the receiver.Stops a given object from receiving change notifications for the property specified by a given key-path relative to the receiver and a context.Sets the observation info for the receiver. Invoked to inform the receiver that the specified change is about to be executed at given indexes for a specified ordered to-many relationship.Invoked to inform the receiver that the value of a given property is about to change.Invoked to inform the receiver that the specified change is about to be made to a specified unordered to-many relationship.These constants are returned as the value for a NSKeyValueChangeKindKey key in the change dictionary passed to observeValueForKeyPath:ofObject:change:context: indicating the type of change made:These constants are passed to addObserver:forKeyPath:options:context: and determine the values that are returned as part of the change dictionary passed to an observeValueForKeyPath:ofObject:change:context:. You can pass 0 if you require no change dictionary values.These constants are used as keys in the change dictionary passed to observeValueForKeyPath:ofObject:change:context:.These constants are specified as the parameter to the methods willChangeValueForKey:withSetMutation:usingObjects: and didChangeValueForKey:withSetMutation:usingObjects:. Their semantics correspond exactly to the NSMutableSet class methods unionSet:, minusSet:, intersectSet:, and setSet: method, respectively.
Class Method Summary (collapse)
-
+ automaticallyNotifiesObserversForKey:
Returns a Boolean value that indicates whether the receiver supports automatic key-value observation for the given key.
-
+ keyPathsForValuesAffectingValueForKey:
Returns a set of key paths for properties whose values affect the value of the specified key.
Instance Method Summary (collapse)
-
- addObserver:forKeyPath:options:context:
Registers anObserver to receive KVO notifications for the specified key-path relative to the receiver.
-
- didChange:valuesAtIndexes:forKey:
Invoked to inform the receiver that the specified change has occurred on the indexes for a specified ordered to-many relationship.
-
- didChangeValueForKey:
Invoked to inform the receiver that the value of a given property has changed.
-
- didChangeValueForKey:withSetMutation:usingObjects:
Invoked to inform the receiver that the specified change was made to a specified unordered to-many relationship.
-
- observationInfo
Returns a pointer that identifies information about all of the observers that are registered with the receiver.
-
- observeValueForKeyPath:ofObject:change:context:
This message is sent to the receiver when the value at the specified key path relative to the given object has changed.
-
- removeObserver:::
Stops a given object from receiving change notifications for the property specified by a given key-path relative to the receiver and a context.
-
- removeObserver:forKeyPath:
Stops a given object from receiving change notifications for the property specified by a given key-path relative to the receiver.
-
- setObservationInfo:
Sets the observation info for the receiver.
-
- willChange:valuesAtIndexes:forKey:
Invoked to inform the receiver that the specified change is about to be executed at given indexes for a specified ordered to-many relationship.
-
- willChangeValueForKey:
Invoked to inform the receiver that the value of a given property is about to change.
-
- willChangeValueForKey:withSetMutation:usingObjects:
Invoked to inform the receiver that the specified change is about to be made to a specified unordered to-many relationship.
Class Method Details
+ (Boolean) automaticallyNotifiesObserversForKey(key)
Returns a Boolean value that indicates whether the receiver supports automatic key-value observation for the given key. The default implementation returns YES.
+ (NSSet) keyPathsForValuesAffectingValueForKey(key)
Returns a set of key paths for properties whose values affect the value of
the specified key. When an observer for the key is registered with an
instance of the receiving class, key-value observing itself automatically
observes all of the key paths for the same instance, and sends change
notifications for the key to the observer when the value for any of those
key paths changes.The default implementation of this method searches the
receiving class for a method whose name matches the pattern
+keyPathsForValuesAffecting
Instance Method Details
- (Object) addObserver(anObserver, forKeyPath:keyPath, options:options, context:context)
Registers anObserver to receive KVO notifications for the specified key-path relative to the receiver. Neither the receiver, nor anObserver, are retained.
- (Object) didChange(change, valuesAtIndexes:indexes, forKey:key)
Invoked to inform the receiver that the specified change has occurred on the indexes for a specified ordered to-many relationship. You should invoke this method when implementing key-value-observing compliance manually.
- (Object) didChangeValueForKey(key)
Invoked to inform the receiver that the value of a given property has changed. You should invoke this method when implementing key-value observer compliance manually.
- (Object) didChangeValueForKey(key, withSetMutation:mutationKind, usingObjects:objects)
Invoked to inform the receiver that the specified change was made to a specified unordered to-many relationship. You invoke this method when implementing key-value observer compliance manually.
- (Object) observationInfo
Returns a pointer that identifies information about all of the observers that are registered with the receiver. The default implementation of this method retrieves the information from a global dictionary keyed by the receiver’s pointers. For improved performance, this method and setObservationInfo: can be overridden to store the opaque data pointer in an instance variable. Overrides of this method must not attempt to send Objective-C messages to the stored data, including retain and release.
- (Object) observeValueForKeyPath(keyPath, ofObject:object, change:change, context:context)
This message is sent to the receiver when the value at the specified key path relative to the given object has changed. The receiver must be registered as an observer for the specified keyPath and object.
- (Object) removeObserver(observerforKeyPath, :keyPathcontext, :context)
Stops a given object from receiving change notifications for the property specified by a given key-path relative to the receiver and a context. 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.
- (Object) removeObserver(anObserver, forKeyPath:keyPath)
Stops a given object from receiving change notifications for the property specified by a given key-path relative to the receiver.
- (Object) setObservationInfo(observationInfo)
Sets the observation info for the receiver. The observationInfo is a pointer that identifies information about all of the observers that are registered with the receiver. The default implementation of this method stores observationInfo in a global dictionary keyed by the receiver’s pointers.For improved performance, this method and observationInfo can be overridden to store the opaque data pointer in an instance variable. Classes that override this method must not attempt to send Objective-C messages to observationInfo, including retain and release.
- (Object) willChange(change, valuesAtIndexes:indexes, forKey:key)
Invoked to inform the receiver that the specified change is about to be executed at given indexes for a specified ordered to-many relationship. You should invoke this method when implementing key-value-observing compliance manually. Important: After the values have been changed, a corresponding didChange:valuesAtIndexes:forKey: must be invoked with the same parameters.
- (Object) willChangeValueForKey(key)
Invoked to inform the receiver that the value of a given property is about to change. You should invoke this method when implementing key-value observer compliance manually.The change type of this method is NSKeyValueChangeSetting.Important: After the values have been changed, a corresponding didChangeValueForKey: must be invoked with the same parameter.
- (Object) willChangeValueForKey(key, withSetMutation:mutationKind, usingObjects:objects)
Invoked to inform the receiver that the specified change is about to be made to a specified unordered to-many relationship. You invoke this method when implementing key-value observer compliance manually.Important: After the values have been changed, a corresponding didChangeValueForKey:withSetMutation:usingObjects: must be invoked with the same parameters.