Instance Method

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

func expectation(description: String) -> XCTestExpectation

Creates a new expectation with an associated description.

func expectation(for: NSPredicate, evaluatedWith: Any?, handler: XCTNSPredicateExpectation.Handler?) -> XCTestExpectation

Creates an expectation that is fulfilled if the predicate returns true when evaluated with the given object.

func keyValueObservingExpectation(for: Any, keyPath: String, handler: XCTKVOExpectation.Handler?) -> XCTestExpectation

Creates an expectation that uses Key Value Observing to observe a value and respond to changes in that value by calling a provided handler.