Reputation: 29
I am trying to make a countdown timer that stops when it has gone down to 0 seconds. Every thing works except that it should stop at o seconds.
please answer if you know why the error occurred or how to solve it.
func stopAt() {
if countLabel.text = "0" {
if timerRunning == true {
timer.invalidate()
timerRunning = false
}
}
}
Upvotes: 0
Views: 648
Reputation: 130092
=
is assignment, ==
is comparison. You want to compare countLabel.text
with "0"
, not assign "0"
to countLabel.text
.
func stopAt() {
if countLabel.text == "0" {
if timerRunning {
timer.invalidate()
timerRunning = false
}
}
}
Also, you never need to compare with true
or false
explicitely.
Upvotes: 3