<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.0.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSArray/addObserver(_:forKeyPath:options:context:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSArray(im)addObserver:forKeyPath:options:context:"
  },
  "title" : "addObserver(_:forKeyPath:options:context:)"
}
-->

# addObserver(_:forKeyPath:options:context:)

Raises an exception.

```
func addObserver(_ observer: NSObject, forKeyPath keyPath: String, options: NSKeyValueObservingOptions = [], context: UnsafeMutableRawPointer?)
```

## Parameters

`observer`

The object to register for KVO notifications. The observer must implement the key-value observing method <doc://com.apple.documentation/documentation/ObjectiveC/NSObject-swift.class/observeValue(forKeyPath:of:change:context:)>.

`keyPath`

The key path, relative to the array, of the property to observe. This value must not be `nil`.

`options`

A combination of [`NSKeyValueObservingOptions`](/documentation/Foundation/NSKeyValueObservingOptions) values that specifies what is included in observation notifications.

`context`

Arbitrary data that is passed to `observer` in <doc://com.apple.documentation/documentation/ObjectiveC/NSObject-swift.class/observeValue(forKeyPath:of:change:context:)>.

## Discussion

`NSArray` objects are not observable, so this method raises an exception when invoked on an `NSArray` object. Instead of observing an array, observe the to-many relationship for which the array is the collection of related objects.

---

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)