I have created a little timer in my Swift application that I want to end when the timer is up. I created an else statement to perform a segue when the timer reaches zero. When that happens, it just keeps refreshing the segue every 1 second so the segue never ends. The code runs fine, I just need to end the update var timer
when the timer reaches 0 so the segue is only performed once instead of over and over again every second. How can I achieve that with the code I have below? I would like this answered in Swift please.
var count = 5
var timer = NSTimer.scheduledTimerWithTimeInterval(1.0, target: self, selector: Selector("update"), userInfo: nil, repeats: true)
func update() {
if (count > 0) {
timer.text = String(count--)
} else if count == 0 {
performSegueWithIdentifier("toResults", sender: self)
}
}