Skip to content

Instantly share code, notes, and snippets.

@nbasham
Last active Jan 29, 2016
Embed
What would you like to do?
Run a block on the main thread after a specified number of seconds.
import Foundation
public class ThreadUtil : NSObject {
// Run a block on the main thread after a specified number of seconds, thanks raywenderlich.com for splaining it so well
public static func runOnMainThreadAfterDelay(delaySeconds: Double, closure: () -> ()) {
let startTime = dispatch_time(DISPATCH_TIME_NOW, Int64(delaySeconds * Double(NSEC_PER_SEC)))
dispatch_after(startTime, dispatch_get_main_queue(), closure)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment