Skip to content

Instantly share code, notes, and snippets.

@qmchenry
Last active June 29, 2016 12:26
Show Gist options
  • Save qmchenry/b235f21ca0a10ac6cbc9fae7585989ad to your computer and use it in GitHub Desktop.
Save qmchenry/b235f21ca0a10ac6cbc9fae7585989ad to your computer and use it in GitHub Desktop.
Example of new Swift 3 swiftier GCD syntax
// Swift 2.x
public class func GCDDelay(delayAmount:Float, block:(Void->Void)) {
dispatch_after(dispatch_time(dispatch_time_t(DISPATCH_TIME_NOW),
Int64(delayAmount * Float(NSEC_PER_SEC))), dispatch_get_main_queue(), block)
}
GCDDelay(0.5) { UIApplication.sharedApplication.openURL(url) }
// Swift 3
public class func GCDDelay(_ delayAmount:Double, block:((Void)->Void)) {
DispatchQueue.main.after(when: .now() + delayAmount, execute: block)
}
// or just this
DispatchQueue.main.after(when: .now() + 0.5) { UIApplication.sharedApplication.openURL(url) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment