iOS - 计时器选择器线程

iOS - Timer selector thread

我有一个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