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

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

Creates an expectation that the system fulfills when the value of the observed property changes to an expected value.

## Declaration

```swift
convenience init(keyPath: KeyPath<T, V>, observedObject: T, options: NSKeyValueObservingOptions = [.initial, .new, .old], expectedValue: V)
```

## Parameters

- `keyPath`: The key path for the observed property, relative to the observed object.
- `observedObject`: The object to observe the key path on.
- `options`: A combination of values that specify what to include in observation notifications. For possible values, see doc://com.apple.documentation/documentation/Foundation/NSKeyValueObservingOptions.
- `expectedValue`: A value that the key path’s specified property must equal to fulfill the expectation.

## Discussion

Discussion Use this initializer to create an expectation that observes changes on the observed object until the value of the property matches the expected value, fulfilling the expectation.

## See Also

### Creating key path expectations

- [init(keyPath:observedObject:options:predicate:)](xctest/xctkeypathexpectation/init(keypath:observedobject:options:predicate:).md)
- [init(keyPath:observedObject:options:filter:)](xctest/xctkeypathexpectation/init(keypath:observedobject:options:filter:)-plka.md)
- [init(keyPath:observedObject:options:filter:)](xctest/xctkeypathexpectation/init(keypath:observedobject:options:filter:)-8noag.md)
- [XCTKeyPathExpectation.AsynchronousFilter](xctest/xctkeypathexpectation/asynchronousfilter.md)
- [XCTKeyPathExpectation.SynchronousFilter](xctest/xctkeypathexpectation/synchronousfilter.md)
- [XCTKeyPathExpectation.Predicate](xctest/xctkeypathexpectation/predicate.md)
