小编Abr*_*ram的帖子

Swift 4 Timer.invalidate()返回"表达式解析为未使用的函数"错误

我正在制作一个游戏,其中有一个计时器显示当前会话已经过了多长时间.我已经按照几个教程阅读文档,似乎无法弄清楚为什么会返回错误.这是我的代码:

var timerT = Timer()

func startTimer () {
    self.timerT = Timer.scheduledTimer(timeInterval: 1.0, target: self, selector: #selector(timeFunc), userInfo: nil, repeats: true)
}

@objc func timeFunc (_ timer: Timer) {
    timeS += 1
}
@IBAction func newGameAction(_ sender: UIButton) {
    Timer.invalidate(timerT)
    game = SetGame()
    updateUIfromModel()
    startTimer()

}
Run Code Online (Sandbox Code Playgroud)

很多Mahalo.

timer ios swift

-3
推荐指数
1
解决办法
286
查看次数

标签 统计

ios ×1

swift ×1

timer ×1