
Creating a delay function
A delay function is something that is always useful. Uses are really countless. Here is one of the best methods I’ve come across. First you create the function:
And then you just use it whenever you need to:
1 2 3 4 5 6 7 |
func delay(delay:Double, closure:()->()) { dispatch_after( dispatch_time( DISPATCH_TIME_NOW, Int64(delay * Double(NSEC_PER_SEC))), dispatch_get_main_queue(), closure) } |
1 2 3 4 5 |
delay(5) { // takes a Double value for the delay in seconds // put the delayed action/function here } |