【发布时间】:2017-02-27 11:09:38
【问题描述】:
如何让我的代码等到 DispatchQueue 中的任务完成?它需要任何 CompletionHandler 什么的吗?
func myFunction() {
var a: Int?
DispatchQueue.main.async {
var b: Int = 3
a = b
}
// wait until the task finishes, then print
print(a) // - this will contain nil, of course, because it
// will execute before the code above
}
我正在使用 Xcode 8.2 并使用 Swift 3 编写代码。
【问题讨论】:
标签: swift multithreading asynchronous swift3 grand-central-dispatch