Created
June 22, 2016 08:09
-
-
Save TheDarkCode/6170f8c185c5aeaead70ee14d64ec840 to your computer and use it in GitHub Desktop.
Delay Utility for GCD in Swift 3
This file contains 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
// | |
// Delay.swift | |
// Delay Utility for GCD in Swift 3 | |
// | |
// Created by Mark Hamilton on 6/21/16. | |
// Copyright © 2016 dryverless. All rights reserved. | |
// | |
/* | |
example: | |
delay(2) { | |
// do after 2 seconds | |
} | |
*/ | |
public func delay(_ delay: Double, closure:(() -> Void)) { | |
// var dispatchTime: DispatchTime = DispatchTime.now() + Double(Int64(delay * Double(NSEC_PER_SEC))) / Double(NSEC_PER_SEC) | |
// DispatchQueue.main.after(when: dispatchTime, execute: closure) | |
DispatchQueue.main.after(when: .now() + delay, execute: closure) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment