Skip to content

Instantly share code, notes, and snippets.

@NxSoftware
Created November 21, 2015 13:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NxSoftware/d54095a9e33c6c6bc8cb to your computer and use it in GitHub Desktop.
Save NxSoftware/d54095a9e33c6c6bc8cb to your computer and use it in GitHub Desktop.
XCTestCase extension for simplifying waiting for expectations
//
// XCTestCase+OffTopic.swift
//
// Created by Steve Wilford on 21/11/2015.
// Copyright © 2015 Off Topic. All rights reserved.
//
import XCTest
extension XCTestCase {
func wait(delay: NSTimeInterval, forExpectationWithDescription description: String, timeout: NSTimeInterval, handler: () -> ()) {
wait(delay, forExpectationWithDescription: description, timeout: timeout, handler: handler, timeoutHandler: nil)
}
func wait(delay: NSTimeInterval, forExpectationWithDescription description: String, timeout: NSTimeInterval, handler: () -> (), timeoutHandler: XCWaitCompletionHandler? = nil) {
let expectation = self.expectationWithDescription(description)
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, Int64(delay * Double(NSEC_PER_SEC))), dispatch_get_main_queue()) {
handler()
expectation.fulfill()
}
self.waitForExpectationsWithTimeout(timeout, handler: timeoutHandler)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment