<!--
{
  "availability" : [
    "*: -",
    "iOS: 13.0.0 -",
    "iPadOS: 13.0.0 -",
    "macCatalyst: 13.0.0 -",
    "tvOS: 13.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "XCTest",
  "identifier" : "/documentation/XCTest/XCTKeyPathExpectation/init(keyPath:observedObject:options:predicate:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "XCTest"
    ],
    "preciseIdentifier" : "s:6XCTest21XCTKeyPathExpectationC03keyC014observedObject7options9predicateACyxq_Gs03KeyC0Cyxq_G_xSo26NSKeyValueObservingOptionsVSbx_10Foundation0kL14ObservedChangeVyq_GtYaYbcSgtcfc"
  },
  "title" : "init(keyPath:observedObject:options:predicate:)"
}
-->

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

Creates an expectation that the system fulfills when the value of the observed property changes and satisfies the conditions of a predicate’s evaluation.

```
convenience init(keyPath: KeyPath<T, V>, observedObject: T, options: NSKeyValueObservingOptions = [.initial, .new, .old], predicate: XCTKeyPathExpectation<T, V>.Predicate? = nil)
```

## 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>.

`predicate`

A closure that evaluates the value of the observed property. If `nil`, the first observed change fulfills the expectation.

## Discussion

Use this initializer to create an expectation that observes changes on the observed object until the predicate returns <doc://com.apple.documentation/documentation/Swift/true>, fulfilling the expectation.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)