【发布时间】:2016-06-14 01:02:49
【问题描述】:
好的,所以我发现了 Xcode 8 中的新 Swifty Dispatch API。我很喜欢使用 DispatchQueue.main.async,并且我一直在浏览 Xcode 中的 Dispatch 模块以查找所有新 API。
但我也使用dispatch_once 来确保不会多次执行诸如单例创建和一次性设置之类的事情(即使在多线程环境中)...并且找不到dispatch_once在新的 Dispatch 模块中?
static var token: dispatch_once_t = 0
func whatDoYouHear() {
print("All of this has happened before, and all of it will happen again.")
dispatch_once(&token) {
print("Except this part.")
}
}
【问题讨论】:
标签: swift grand-central-dispatch swift3 libdispatch