---
title: "addObserver(_:toObjectsAt:forKeyPath:options:context:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/nsarray/addobserver(_:toobjectsat:forkeypath:options:context:)"
---

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

Registers an observer to receive key value observer notifications for the specified key-path relative to the objects at the indexes.

## Declaration

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

## Parameters

- `observer`: The observer.
- `indexes`: The index set.
- `keyPath`: The key path, relative to the array, to be observed.
- `options`: The options to be included in the notification.
- `context`: The context passed to the notifications.

## Discussion

Discussion The options determine what is included in the notifications, and the context is passed in the notifications. This is not merely a convenience method; invoking this method is potentially much faster than repeatedly invoking addObserver(_:forKeyPath:options:context:).

## See Also

### Key-Value Observing

- [addObserver(_:forKeyPath:options:context:)](foundation/nsarray/addobserver(_:forkeypath:options:context:).md)
- [removeObserver(_:forKeyPath:)](foundation/nsarray/removeobserver(_:forkeypath:).md)
- [removeObserver(_:forKeyPath:context:)](foundation/nsarray/removeobserver(_:forkeypath:context:).md)
- [removeObserver(_:fromObjectsAt:forKeyPath:context:)](foundation/nsarray/removeobserver(_:fromobjectsat:forkeypath:context:).md)
- [removeObserver(_:fromObjectsAt:forKeyPath:)](foundation/nsarray/removeobserver(_:fromobjectsat:forkeypath:).md)
