Created
May 21, 2015 18:01
-
-
Save loganwright/39056d582d3a28eb6b32 to your computer and use it in GitHub Desktop.
Dispatching events to later in Swift.
This file contains hidden or 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
func After(after: NSTimeInterval, op: () -> ()) { | |
After(after, op, nil) | |
} | |
func After(after: NSTimeInterval, op: () -> (), completion: (() -> Void)?) { | |
let seconds = Int64(after * Double(NSEC_PER_SEC)) | |
var dispatchTime = dispatch_time(DISPATCH_TIME_NOW, seconds) | |
dispatch_after(dispatchTime, dispatch_get_main_queue()) { | |
let blockOp = NSBlockOperation(block: op) | |
blockOp.completionBlock = completion | |
NSOperationQueue.mainQueue().addOperation(blockOp) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment