我有一个 Swift 代码,
var timer = Timer.scheduledTimer(timeInterval: 1.0, target: self, selector: #selector(self.updateAction), userInfo: nil, repeats: true)
此代码从主线程运行,比方说,viewDidLoad()
。我想知道这个选择器 updateAction()
是否保证在主线程中运行。换句话说,如果我在 updateAction()
中有 UI 操作,我是否应该明确地将代码包装在主线程上。
最佳答案
您的 Timer
将始终在您的主线程上运行,因此您始终可以在 updateAction()
中更新您的 UI。
关于iOS - 计时器选择器线程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44689290/