I know that there are several ways of delaying an action in Objective-C like:
performSelector:withObject:afterDelay:
or using NSTimer
Here is how you can trigger a block after a delay in Swift:
runThisAfterDelay(seconds: 4) { () -> () in
print("Prints this 4 seconds later in main queue")
// Or just call animatedMyObject() right here
}
/// EZSwiftExtensions
func runThisAfterDelay(seconds seconds: Double, after: () -> ()) {
let time = dispatch_time(DISPATCH_TIME_NOW, Int64(seconds * Double(NSEC_PER_SEC)))
dispatch_after(time, dispatch_get_main_queue(), after)
}
Its included as a standard function in my repo: https://github.com/goktugyil/EZSwiftExtensions