【发布时间】:2017-04-23 20:46:38
【问题描述】:
我在func pauseAction 下面的行中收到一个错误,上面写着“预期的声明”,并且有一个箭头指向“计时器”这个词
var timeLeft = 10
var timer = Timer()
var score: Int = 0 {
didSet {
scoreLabel.text = "\(score)"
}
}
@IBOutlet var scoreLabel: UILabel!
@IBAction func tapButton(_ sender: Any) {
score += 1
}
@IBAction func pauseAction(_ sender: Any) {
}
timer = Timer.scheduledTimer(timeInterval: 1.0, target:self, selector: Selector(("updateTimer")), userInfo: nil, repeats: true)
func updateTimer() {
timeLeft -= 1
timeLabel.text = String(timeLeft)
if timeLeft == 0 {
timer.invalidate()
}
}
【问题讨论】: