Created
July 28, 2015 14:19
-
-
Save SlaunchaMan/cc01cc292b87aee6e2ff to your computer and use it in GitHub Desktop.
Swift-friendly dispatch_after()
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
| /** | |
| 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