---
title: "addSharedObserver(_:forKey:options:context:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/nskeyvaluesharedobservers/addsharedobserver(_:forkey:options:context:)"
---

# addSharedObserver(_:forKey:options:context:)

Add a new observer to the collection.

## Declaration

```swift
func addSharedObserver(_ observer: NSObject, forKey key: String, options: NSKeyValueObservingOptions = [], context: UnsafeMutableRawPointer?)
```

## Parameters

- `observer`: The observer object to register for KVO notifications. The observer must implement the key-value observing method observeValue: forKeyPath: of: change: context:
- `key`: Key of the property being observed. This cannot be a nested key path or a computed property
- `options`: A combination of NSKeyValueObservingOptions values that specify what is included in observation notifications. For possible values see NSKeyValueObservingOptions.
- `context`: Arbitrary data which is passed to the observer object

## Discussion

Discussion This method works like -[NSObject addObserver: forKey: options: context:], but observations on nested and computed properties are disallowed. Observers are not registered until setSharedObservers is called on the observable.
