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

# handler

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

```
var handler: XCTKVOExpectation.Handler? { get set }
```

## Discussion

> Note:
> The system ignores the expectation’s ``doc://com.apple.xctest/documentation/XCTest/XCTKVOExpectation/expectedValue`` property when the ``doc://com.apple.xctest/documentation/XCTest/XCTKVOExpectation/handler-swift.property`` is non-nil.

---

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)