<分区>
我是编码(和这个网站)的新手,我正在尝试使用 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()
}
}