Instance Method

expectation(for:evaluatedWith:handler:)

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

Declaration

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

Parameters

predicate

The predicate to evaluate.

object

The object against which the predicate is evaluated.

handler

An optional handler that performs custom evaluation when predicate evaluates as true.

Discussion

The expectation periodically evaluates the predicate and also may use notifications or other events to optimistically re-evaluate.

If a handler is not provided, the first successful evaluation of the predicate will fulfill the expectation. If a handler is provided, the handler can override this default behavior and tailor the conditions under which the expectation should be considered fulfilled.

See Also

Creating Asynchronous Test Expectations

func expectation(description: String)

Creates a new expectation with an associated description.

func keyValueObservingExpectation(for: Any, keyPath: String, expectedValue: Any?)

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

func keyValueObservingExpectation(for: Any, keyPath: String, handler: XCTKVOExpectation.Handler? = nil)

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