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

# init(keyPath:object:expectedValue:options:)

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

## Declaration

```swift
init(keyPath: String, object: Any, expectedValue: Any?, options: NSKeyValueObservingOptions = [])
```

## Parameters

- `keyPath`: The key path to observe.
- `object`: The object to observe.
- `expectedValue`: The expected value for the observed key path.
- `options`: An array of doc://com.apple.documentation/documentation/Foundation/NSKeyValueObservingOptions that determine the values to return as part of the observed key path’s change dictionary.

## See Also

### Creating KVO expectations

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