I am trying to perform segue right after the timer reach 0. My code as below for the timer in the viewDidLoad:
override func viewDidLoad() {
super.viewDidLoad()
if timerRunning == false {
timerCounter = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(Counting), userInfo: nil, repeats: true)
timerRunning = true
}
if counter == 0 {
timerRunning = false
}
and this is the function counter:
func Counting() {
counter -= 1
timer.text = "\(counter)"
if counter == 0 {
timerCounter.invalidate()
timerRunning = false
self.performSegue(withIdentifier: "resultView", sender: self)
}
}