Skip to content

Instantly share code, notes, and snippets.

@barbietunnie
Created July 14, 2015 03:06
Show Gist options
  • Save barbietunnie/51e330a491571c441c7e to your computer and use it in GitHub Desktop.
Save barbietunnie/51e330a491571c441c7e to your computer and use it in GitHub Desktop.
/**
* Delay the block specified by delay seconds
*
* With help from http://stackoverflow.com/questions/24034544/dispatch-after-gcd-in-swift/24318861#24318861
*/
func delay(delay:Double, closure:()->()) {
dispatch_after(
dispatch_time(
DISPATCH_TIME_NOW,
Int64(delay * Double(NSEC_PER_SEC))
),
dispatch_get_main_queue(), closure)
}
// Usage
delay(0.4) {
// do stuff
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment