【发布时间】:2023-03-02 22:42:01
【问题描述】:
我是编码新手(和这个网站),我正在尝试使用 YouTube 上的教程构建秒表,但我无法让它工作。当我编写更新定时器的函数时,第 6 行和第 7 行显示错误“% 不可用:改用 truncatingRemainder”。我正在使用最新的 Xcode 版本在最新版本的 Swift 中进行编码。有人可以告诉我如何让它在毫秒内与 truncatingRemainder 一起工作吗?我真的很感激。
这里是教程的链接:https://www.youtube.com/watch?v=xp0dvmvh3Cw
func updateElapsedTimeLabel (timer : Timer)
{
if watch.isRunning
{
let minutes = Int(watch.elapsd/60)
let seconds = Int(watch.elapsd % 60)
let ten0fseconds = Int(watch.elapsd * 10 % 10)
elapsedTimeLabel.text = String (format: "%2d:%2d.%2d", minutes, seconds, ten0fseconds)
}
else {
timer.invalidate()
}
}
【问题讨论】:
-
错误信息告诉你该怎么做...
-
@Code-Apprentice 我知道它会告诉我,但我想知道它为什么不起作用。