简体   繁体   中英

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                    
        }       
    }        
}

= 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM