---
title: "removeObserver(_:forKeyPath:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/nsset/removeobserver(_:forkeypath:)"
---

# removeObserver(_:forKeyPath:)

Raises an exception.

## Declaration

```swift
func removeObserver(_ observer: NSObject, forKeyPath keyPath: String)
```

## Parameters

- `observer`: The object to remove as an observer.
- `keyPath`: A key-path, relative to the set, for which observer is registered to receive KVO change notifications. This value must not be nil.

## Discussion

Discussion NSSet objects are not observable, so this method raises an exception when invoked on an NSSet object. Instead of observing a set, observe the unordered to-many relationship for which the set is the collection of related objects.

## See Also

### Key-Value Observing

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