<!--
{
  "availability" : [
    "iOS: -",
    "iPadOS: -",
    "macCatalyst: -",
    "macOS: -",
    "tvOS: -",
    "visionOS: -",
    "watchOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "XCTest",
  "identifier" : "/documentation/XCTest/XCTKVOExpectation/init(keyPath:object:expectedValue:options:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "XCTest"
    ],
    "preciseIdentifier" : "c:objc(cs)XCTKVOExpectation(im)initWithKeyPath:object:expectedValue:options:"
  },
  "title" : "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.

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

## Discussion

---

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)