Skip to content

Instantly share code, notes, and snippets.

@SlaunchaMan
Created July 28, 2015 14:19
Show Gist options
  • Select an option

  • Save SlaunchaMan/cc01cc292b87aee6e2ff to your computer and use it in GitHub Desktop.

Select an option

Save SlaunchaMan/cc01cc292b87aee6e2ff to your computer and use it in GitHub Desktop.
Swift-friendly dispatch_after()
/**
Shadows the system’s `dispatch_after()` function with a friendlier syntax for Swift.
Performs the `block` on `queue` after `delay` seconds.
:param: delay The delay (in seconds). Defaults to 0.1 seconds.
:param: queue The dispatch queue to perform the work on. Defaults to the main queue.
:param: block The block to execute after the delay.
*/
public func dispatch_after(delayInSeconds delay: NSTimeInterval = 0.1,
queue: dispatch_queue_t = dispatch_get_main_queue(),
block: dispatch_block_t) {
let time = dispatch_time(DISPATCH_TIME_NOW,
Int64(NSTimeInterval(NSEC_PER_SEC) * delay))
dispatch_after(time, queue, block)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment