Skip to content

Instantly share code, notes, and snippets.

@glowcap
Last active August 16, 2017 07:07
Show Gist options
  • Select an option

  • Save glowcap/b1cd41d5bf7d4105dca8608c39eb8430 to your computer and use it in GitHub Desktop.

Select an option

Save glowcap/b1cd41d5bf7d4105dca8608c39eb8430 to your computer and use it in GitHub Desktop.
Swift3 trigger method after delay
// 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