Contents

keyValueObservingExpectation(for:keyPath:expectedValue:)

Creates an expectation that uses Key-Value Observing to observe a value until it matches an expected value.

Declaration

func keyValueObservingExpectation(for objectToObserve: Any, keyPath: String, expectedValue: Any?) -> XCTestExpectation

Parameters

  • objectToObserve:

    The object to observe.

  • keyPath:

    The key path to observe.

  • expectedValue:

    Expected value of the value specified by keyPath. The expectation will fulfill itself when the value at keyPath is equal to expectedValue, as tested using isEqual:. If expectedValue is nil, the expectation will be fulfilled by the first change to the key path of the observed object.

Return Value

Creates and returns an expectation associated with the test case.

Discussion

Creates an XCTestExpectation that uses Key Value Observing to observe changes on the provided object until the value specified by keyPath matches the expected value using isEqual:.

See Also

Creating Asynchronous Test Expectations