Last active
June 29, 2016 12:26
-
-
Save qmchenry/b235f21ca0a10ac6cbc9fae7585989ad to your computer and use it in GitHub Desktop.
Example of new Swift 3 swiftier GCD syntax
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
// 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