
Delay Function in Swift 3.0
Since thing have changed a lot for Swift 3.0 , here is a quick tip on how to create a delayed function with the new API. Add this function to your project:
Then if you want to launch anything after a delay, you use it like so:
That’s all 🙂 Cheers!
1 2 3 4 5 6 7 |
func delay(time: Double, closure:()->()) { DispatchQueue.main.after(when: .now() + time) { closure() } } |
1 2 3 4 |
delay(time: 10) { print("hello") } |