<!--
{
  "documentType" : "article",
  "framework" : "ObjectiveC",
  "identifier" : "/documentation/ObjectiveC/nskeyvalueobserving",
  "metadataVersion" : "0.1.0",
  "role" : "collectionGroup",
  "title" : "NSKeyValueObserving"
}
-->

# NSKeyValueObserving

An informal protocol that objects adopt to be notified of changes to the specified properties of other objects.

## Discussion

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`](/documentation/ObjectiveC/NSObject-swift.class) provides an implementation of the [NSKeyValueObserving](/documentation/ObjectiveC/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

[`observeValue(forKeyPath:of:change:context:)`](/documentation/ObjectiveC/NSObject-swift.class/observeValue(forKeyPath:of:change:context:))

Informs the observing object when the value at the specified key path relative to the observed object has changed.

### Registering for Observation

[`addObserver(_:forKeyPath:options:context:)`](/documentation/ObjectiveC/NSObject-swift.class/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:)`](/documentation/ObjectiveC/NSObject-swift.class/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.

[`removeObserver(_:forKeyPath:context:)`](/documentation/ObjectiveC/NSObject-swift.class/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.

### Notifying Observers of Changes

[`willChangeValue(forKey:)`](/documentation/ObjectiveC/NSObject-swift.class/willChangeValue(forKey:))

Informs the observed object that the value of a given property is about to change.

[`didChangeValue(forKey:)`](/documentation/ObjectiveC/NSObject-swift.class/didChangeValue(forKey:))

Informs the observed object that the value of a given property has changed.

[`willChange(_:valuesAt:forKey:)`](/documentation/ObjectiveC/NSObject-swift.class/willChange(_:valuesAt:forKey:))

Informs the observed object that the specified change is about to be executed at given indexes for a specified ordered to-many relationship.

[`didChange(_:valuesAt:forKey:)`](/documentation/ObjectiveC/NSObject-swift.class/didChange(_:valuesAt:forKey:))

Informs the observed object that the specified change has occurred on the indexes for a specified ordered to-many relationship.

[`willChangeValue(forKey:withSetMutation:using:)`](/documentation/ObjectiveC/NSObject-swift.class/willChangeValue(forKey:withSetMutation:using:))

Informs the observed object that the specified change is about to be made to a specified unordered to-many relationship.

[`didChangeValue(forKey:withSetMutation:using:)`](/documentation/ObjectiveC/NSObject-swift.class/didChangeValue(forKey:withSetMutation:using:))

Informs the observed object that the specified change was made to a specified unordered to-many relationship.

### Observing Customization

[`automaticallyNotifiesObservers(forKey:)`](/documentation/ObjectiveC/NSObject-swift.class/automaticallyNotifiesObservers(forKey:))

Returns a Boolean value that indicates whether the observed object supports automatic key-value observation for the given key.

[`keyPathsForValuesAffectingValue(forKey:)`](/documentation/ObjectiveC/NSObject-swift.class/keyPathsForValuesAffectingValue(forKey:))

Returns a set of key paths for properties whose values affect the value of the specified key.

  <doc://com.apple.documentation/documentation/Foundation/NSKeyValueObservingCustomization>

[`setKeys:triggerChangeNotificationsForDependentKey:`](/documentation/ObjectiveC/NSObject-swift.class/setKeys:triggerChangeNotificationsForDependentKey:)

Configures the observed object to post change notifications for a given property if any of the properties specified in a given array changes.

[`observationInfo`](/documentation/ObjectiveC/NSObject-swift.class/observationInfo)

Returns a pointer that identifies information about all of the observers that are registered with the observed object.

### Constants

  <doc://com.apple.documentation/documentation/Foundation/NSKeyValueObservation>

  <doc://com.apple.documentation/documentation/Foundation/NSKeyValueObservedChange>

  <doc://com.apple.documentation/documentation/Foundation/NSKeyValueChange>

  <doc://com.apple.documentation/documentation/Foundation/NSKeyValueObservingOptions>

  <doc://com.apple.documentation/documentation/Foundation/NSKeyValueChangeKey>

  <doc://com.apple.documentation/documentation/Foundation/NSKeyValueSetMutationKind>

## See Also

  [Key-Value Observing Programming Guide](https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/KeyValueObserving/KeyValueObserving.html#//apple_ref/doc/uid/10000177i)



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)