the young programmer
the young programmer

Reputation: 29

Type '()' does not conform to protocol 'BooleanType'

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

Answers (1)

Sulthan
Sulthan

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

Related Questions