Skip to content

Instantly share code, notes, and snippets.

@jonathan-beebe
Created May 16, 2016 16:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonathan-beebe/e3e7cf0c43b7ca2c3917d462329c0545 to your computer and use it in GitHub Desktop.
Save jonathan-beebe/e3e7cf0c43b7ca2c3917d462329c0545 to your computer and use it in GitHub Desktop.
Helpers to make dispach_* code in Swift a bit more concise.
import Foundation
func async(callback:(Void -> Void)) {
dispatch_async(dispatch_get_main_queue(), { () -> Void in
callback()
})
}
func after(delay:Double, closure:Void->Void) {
dispatch_after(
dispatch_time(
DISPATCH_TIME_NOW,
Int64(delay * Double(NSEC_PER_SEC))
),
dispatch_get_main_queue(),
closure
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment