Skip to content

Instantly share code, notes, and snippets.

@nbasham
Last active January 29, 2016 23:21
Show Gist options
  • Save nbasham/6cb30a2a898d9a862497 to your computer and use it in GitHub Desktop.
Save nbasham/6cb30a2a898d9a862497 to your computer and use it in GitHub Desktop.
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