<!--
{
  "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",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "XCTest"
    ],
    "preciseIdentifier" : "s:6XCTest21XCTKeyPathExpectationC"
  },
  "title" : "XCTKeyPathExpectation"
}
-->

# XCTKeyPathExpectation

An expectation that a specific key-value observing (KVO) condition fulfills.

```
final class XCTKeyPathExpectation<T, V> where T : NSObject
```

## Overview

Use an instance of this class to asynchronously wait for changes to a property you specify by key path for a given object. When the value of the property changes, the expectation compares the new value using a predicate or expected value you provide.

## Topics

### Creating key path expectations

[`init(keyPath:observedObject:options:expectedValue:)`](/documentation/XCTest/XCTKeyPathExpectation/init(keyPath:observedObject:options:expectedValue:))

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

[`init(keyPath:observedObject:options:predicate:)`](/documentation/XCTest/XCTKeyPathExpectation/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.

[`init(keyPath:observedObject:options:filter:)`](/documentation/XCTest/XCTKeyPathExpectation/init(keyPath:observedObject:options:filter:)-plka)

[`init(keyPath:observedObject:options:filter:)`](/documentation/XCTest/XCTKeyPathExpectation/init(keyPath:observedObject:options:filter:)-8noag)

[`XCTKeyPathExpectation.AsynchronousFilter`](/documentation/XCTest/XCTKeyPathExpectation/AsynchronousFilter)

[`XCTKeyPathExpectation.SynchronousFilter`](/documentation/XCTest/XCTKeyPathExpectation/SynchronousFilter)

[`XCTKeyPathExpectation.Predicate`](/documentation/XCTest/XCTKeyPathExpectation/Predicate)

A function the key path expectation uses to test the value of an observed property.

### Expectation properties

[`keyPath`](/documentation/XCTest/XCTKeyPathExpectation/keyPath)

The key path for the observed property, relative to the observed object.

[`observedObject`](/documentation/XCTest/XCTKeyPathExpectation/observedObject)

The object the system observes the key path on.

[`options`](/documentation/XCTest/XCTKeyPathExpectation/options)

A combination of values that specify what to include in observation notifications.

[`expectedValue`](/documentation/XCTest/XCTKeyPathExpectation/expectedValue)

A value that the key path’s specified property must equal to fulfill the expectation.

## See Also

  <doc://com.apple.documentation/documentation/Swift/using-key-value-observing-in-swift>



---

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)