Is there any way to use dispatch_after
within a loop? I have the delay function below:
func delay(delay:Double, closure:()->()) {
dispatch_after(
dispatch_time(
DISPATCH_TIME_NOW,
Int64(delay * Double(NSEC_PER_SEC))
),
dispatch_get_main_queue(), closure)
}
I want to execute it inside of a loop like this:
while true {
self.delay(1.0) {
// Do something repeatedly
}
}
But I can't seem to get it working. Is it possible to do this?