Skip to content

Instantly share code, notes, and snippets.

@mmcbrear
Created November 6, 2015 18:55
Show Gist options
  • Save mmcbrear/d0e929b5fbb6173ef620 to your computer and use it in GitHub Desktop.
Save mmcbrear/d0e929b5fbb6173ef620 to your computer and use it in GitHub Desktop.
//
// GCD+Utils.swift
// -
//
//
// Use:
// ASyncMain() {
// your code executed on main thread
// }
//
// Use:
// ASyncAfter(0.5) {
// your code executed main thread after 0.5s
// }
extension NSObject {
func ASyncMain(block: dispatch_block_t) {
dispatch_async(dispatch_get_main_queue(), block)
}
func ASyncAfter(after: Double, block: dispatch_block_t) {
dispatch_after(
dispatch_time(DISPATCH_TIME_NOW, Int64(after * Double(NSEC_PER_SEC))),
dispatch_get_main_queue(),
block)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment