---
title: "init(keyPath:object:)"
framework: xctest
role: symbol
role_heading: Initializer
path: "xctest/xctkvoexpectation/init(keypath:object:)"
---

# init(keyPath:object:)

Creates an expectation that any KVO change to the specified key path of the observed object fulfills.

## Declaration

```swift
convenience init(keyPath: String, object: Any)
```

## Parameters

- `keyPath`: The key path to observe.
- `object`: The object to observe.

## Discussion

Discussion This initializer sets up KVO observation for keyPath with the following NSKeyValueObservingOptions: new old The inclusion of the new and old options means that any custom KVO handler you provide in the expectation’s handler property receives a change info dictionary that contains the newKey and oldKey keys.

## See Also

### Creating KVO expectations

- [init(keyPath:object:expectedValue:)](xctest/xctkvoexpectation/init(keypath:object:expectedvalue:).md)
- [init(keyPath:object:expectedValue:options:)](xctest/xctkvoexpectation/init(keypath:object:expectedvalue:options:).md)
