-performSelector:withObject:afterDelay:
isn't available in Swift. Generally, it's a bad idea to use -performSelector:
and it's variants, but there are exceptions, especially since not all code ends up in production. I find it particularly helpful during development to use it to auto-navigate to the screen I am currently working on. Courtesy of Stack Overflow, in Swift, we can use dispatch_time()
to build something similar.
func delay(delay:Double, closure:()->()) {
dispatch_after(
dispatch_time(DISPATCH_TIME_NOW, Int64(delay * Double(NSEC_PER_SEC))),
dispatch_get_main_queue(),
closure)
}
and call it like this:
delay(0.7) {
//do something here
}
Your feedback is valuable: Do you want more nuggets like this? Yes or No
.
.