<!--
{
  "availability" : [
    "iOS: -",
    "iPadOS: -",
    "macCatalyst: -",
    "macOS: -",
    "tvOS: -",
    "visionOS: -",
    "watchOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "XCTest",
  "identifier" : "/documentation/XCTest/XCTKVOExpectation",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "XCTest"
    ],
    "preciseIdentifier" : "c:objc(cs)XCTKVOExpectation"
  },
  "title" : "XCTKVOExpectation"
}
-->

# XCTKVOExpectation

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

```
class XCTKVOExpectation
```

## Overview

Apple discourages the use of this symbol in Swift. Use [`XCTKeyPathExpectation`](/documentation/XCTest/XCTKeyPathExpectation) instead.

## Topics

### Creating KVO expectations

[`-  initWithKeyPath:object:`](/documentation/XCTest/XCTKVOExpectation/init(keyPath:object:))

Creates an expectation that any KVO change to the specified key path of the observed object fulfills.

[`-  initWithKeyPath:object:expectedValue:`](/documentation/XCTest/XCTKVOExpectation/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.

[`-  initWithKeyPath:object:expectedValue:options:`](/documentation/XCTest/XCTKVOExpectation/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.

### Expectation properties

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

The key path the system observes for KVO changes.

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

The object that the system observes for KVO changes.

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

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

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

The key-value observing options the expectation uses when registering for observation.

### Custom KVO evaluation

[`handler`](/documentation/XCTest/XCTKVOExpectation/handler-swift.property)

An optional handler that performs custom evaluation of changes to the observed key path.

[`Handler`](/documentation/XCTest/XCTKVOExpectation/Handler-swift.typealias)

A custom handler to call when observing a KVO change for a specified key path.

## Relationships

### Conforms To

[`CustomStringConvertible`](/documentation/Swift/CustomStringConvertible)

[`CustomDebugStringConvertible`](/documentation/Swift/CustomDebugStringConvertible)

[`Equatable`](/documentation/Swift/Equatable)

[`NSObjectProtocol`](/documentation/ObjectiveC/NSObjectProtocol)

[`CVarArg`](/documentation/Swift/CVarArg)

[`Hashable`](/documentation/Swift/Hashable)

[`Sendable`](/documentation/Swift/Sendable)

[`SendableMetatype`](/documentation/Swift/SendableMetatype)

### Inherits From

[`XCTestExpectation`](/documentation/XCTest/XCTestExpectation)

---

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)