I use an animation for specify a tip to help the interaction with delay using these:
let delay = 1.8 * Double(NSEC_PER_SEC)
let time = dispatch_time(DIS
Just sharing, in Swift 4.x, I do this:
var block: DispatchWorkItem?
self.block = DispatchWorkItem { self.go(self) }
// execute task in 2 seconds
DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(3), execute: self.block!)
and then to cancel the block, self.block?.cancel()
Try this sample project:
import UIKit
class ViewController: UIViewController {
var block: DispatchWorkItem?
@IBAction func go(_ sender: Any) {
self.block?.cancel()
let vc2 = VC2()
self.navigationController?.pushViewController(vc2, animated: true)
}
override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = .white
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
self.block = DispatchWorkItem { self.go(self) }
// execute task in 2 seconds
DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(3), execute: self.block!)
}
}
class VC2: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = .green
}
}