I want to implement NSTimer.scheduledTimerWithTimeInterval in Swift 3. I want to know the Replacement of
NSTimer.scheduledTimerWithTimeInterval(0.35, target: self, selector: #selector(createEnemy), userInfo: nil, repeats: true)
as we used it in swift 2.2
A Basic timer is declared as such: //declare blank timer variable var timer = Timer() //in a function or viewDidLoad() timer = Timer. scheduledTimer(timeInterval: 1.0, target: self, selector: #selector(timerAction), userInfo: nil, repeats: true) //new function @objc func timerAction(){ print(“timer fired!”) }
Try like this:
Timer.scheduledTimer(timeInterval: 0.35, target: self, selector: #selector(createEnemy), userInfo: nil, repeats: true)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With