Last active
August 16, 2017 07:07
-
-
Save glowcap/b1cd41d5bf7d4105dca8608c39eb8430 to your computer and use it in GitHub Desktop.
Swift3 trigger method after delay
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
| // I always forget how to write this stupid thing | |
| // now I just have to remember I put it here | |
| /// This function calls a closure after a delay. | |
| /// Use it when you want to wait for a certain amount of | |
| /// time before letting an action run | |
| /// | |
| /// - Parameters: | |
| /// - delay: seconds you want to wait | |
| /// - closure: the function you want to run after the delay | |
| func after(delay:Double, closure:@escaping ()->()) { | |
| DispatchQueue.main.asyncAfter(deadline: .now() + delay) { | |
| closure() | |
| } | |
| } | |
| // used like this: | |
| /* | |
| after(delay: 10.0) { | |
| // do something | |
| } | |
| */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment