我正在尝试制作一个倒数计时器,当倒数到 0 秒时停止。一切正常,除了它应该在 o 秒停止。
如果您知道错误发生的原因或如何解决,请回答。
func stopAt() {
if countLabel.text = "0" {
if timerRunning == true {
timer.invalidate()
timerRunning = false
}
}
}
最佳答案
=
是赋值,==
是比较。您想要比较 countLabel.text
与“0”
,而不是赋值 “0”
到 countLabel.text
。
func stopAt() {
if countLabel.text == "0" {
if timerRunning {
timer.invalidate()
timerRunning = false
}
}
}
此外,您永远不需要明确地与 true
或 false
进行比较。
关于swift - 类型 '()' 不符合协议(protocol) 'BooleanType',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32996611/