为什么我的计时器的公差总是减半?

时间:2019-05-10 19:12:50

标签: ios timer nstimer foundation

在我的应用中,我正在安排这样的计时器:

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的一半。这是为什么?这还会产生我想要的功能吗?如果没有,如何防止这种情况发生?

0 个答案:

没有答案
相关问题