---
title: "wait(for:timeout:)"
framework: xctest
role: symbol
role_heading: Instance Method
path: "xctest/xctwaiter/wait(for:timeout:)-swift.method"
---

# wait(for:timeout:)

Waits on a group of expectations for up to the specified timeout.

## Declaration

```swift
func wait(for expectations: [XCTestExpectation], timeout seconds: TimeInterval) -> XCTWaiter.Result
```

## Parameters

- `expectations`: An array of expectations the test must satisfy.
- `seconds`: The time, in seconds, the test allows for the fulfillment of the expectations. The default timeout allows the test to run until it reaches its execution time allowance.

## Return Value

Return Value A value describing the outcome of waiting for expectations.

## Discussion

Discussion The following example demonstrates how to wait on exceptions with a timeout specified: - (void)testSprockets {     NSSprocket *sprocket = [[NSSprocket alloc] init];          XCTestExpectation *sprocketLoaded = [self expectationWithDescription:@"sprocket loaded"];     [sprocket loadUsingBlock:^ (NSUInteger toothCount) {         if (toothCount == 6) {             [sprocketLoaded fulfill];         }     }];

// This usually takes a while. Wait 10s.     [self waitForExpectations:@[sprocketLoaded] timeout:10.0];

id orbitWobbled = [self keyValueObservingExpectationForObject:sprocket                                                           keyPath:@"orbitAngle.doubleValue"                                                     expectedValue:@90.0];     dispatch_async(myQueue, ^ {         [sprocket wobbleOrbit];     });     // Don't know how long to wait, but this is usually fast?     [self waitForExpectations:@[orbitWobbled] timeout:0.1]; } Expectations can appear in the expectations array only once. The call may return before the timeout if the test fulfills all the expectations you provide. In Objective-C code, you might use an expectation to wait on a call to an interface that uses a completion handler to return a result. From Swift code, consider calling withCheckedContinuation(function:_:) to use Concurrency instead of an expectation to wait on the result of a completion handler.

## See Also

### Waiting for Expectations

- [fulfillment(of:timeout:enforceOrder:)](xctest/xctwaiter/fulfillment(of:timeout:enforceorder:)-swift.method.md)
- [wait(for:)](xctest/xctwaiter/wait(for:)-swift.method.md)
- [wait(for:enforceOrder:)](xctest/xctwaiter/wait(for:enforceorder:)-swift.method.md)
- [wait(for:timeout:enforceOrder:)](xctest/xctwaiter/wait(for:timeout:enforceorder:)-swift.method.md)
- [fulfillment(of:timeout:enforceOrder:)](xctest/xctwaiter/fulfillment(of:timeout:enforceorder:)-swift.type.method.md)
- [wait(for:)](xctest/xctwaiter/wait(for:)-swift.type.method.md)
- [wait(for:enforceOrder:)](xctest/xctwaiter/wait(for:enforceorder:)-swift.type.method.md)
- [wait(for:timeout:)](xctest/xctwaiter/wait(for:timeout:)-swift.type.method.md)
- [wait(for:timeout:enforceOrder:)](xctest/xctwaiter/wait(for:timeout:enforceorder:)-swift.type.method.md)
- [XCTWaiter.Result](xctest/xctwaiter/result.md)
