You can use this code for your NSTimer
:
Swift 2
func timer() {
var timer = NSTimer.scheduledTimerWithTimeInterval(2.0, target: self, selector: "timerFunc", userInfo: nil, repeats: false)
}
func timerFunc() {
println("it worked")
}
Swift 3, 4, 5
func timer() {
var timer = Timer.scheduledTimer(timeInterval: 2.0, target: self, selector: #selector(timerFunc), userInfo: nil, repeats: false)
}
@objc func timerFunc() {
print("it worked")
}
You have to use the scheduledTimerWithTimeInterval:target:selector:userInfo:repeats:
class method to run your timer.
Hope this can help you.