在我的应用程序中,我正在安排这样的计时器:
let period = TimeInterval(10)
let timer = Timer.scheduledTimer(withTimeInterval: period, repeats: true, block: { [weak self] (_) in
// Some repeating code here
})
timer.tolerance = period
本质上,我希望计时器在每个连续的时间段内触发一次,重复 10 秒,但计时器在每个单独的时间段内何时触发并不重要。但是,如果我在此代码运行后立即在调试器中设置断点。我可以看到我的计时器timeInterval设置为 10 秒,但计时器tolerance设置为 5。我玩过各种值period,但无论如何,我的计时器似乎总是tolerance它的一半。这是为什么?这仍然会产生我想要的功能吗?如果没有,我该如何防止这种情况发生?timeInterval