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

# init(keyPath:object:expectedValue:)

Creates an expectation a KVO change fulfills when it causes the specified key path of the observed object to have an expected value.

## Declaration

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

## Parameters

- `keyPath`: The key path to observe.
- `object`: The object to observe.
- `expectedValue`: The expected value for the observed key path.

## Discussion

Discussion This initializer sets up KVO observation for keyPath with the following NSKeyValueObservingOptions: initial new old The inclusion of the initial option means that the system checks the observed key path immediately after initialization. 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:)](xctest/xctkvoexpectation/init(keypath:object:).md)
- [init(keyPath:object:expectedValue:options:)](xctest/xctkvoexpectation/init(keypath:object:expectedvalue:options:).md)
