Created
November 21, 2015 13:30
-
-
Save NxSoftware/d54095a9e33c6c6bc8cb to your computer and use it in GitHub Desktop.
XCTestCase extension for simplifying waiting for expectations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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