我怎么能让我的代码等到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
}
Run Code Online (Sandbox Code Playgroud)
我正在使用Xcode 8.2并在Swift 3中编写.
multithreading asynchronous grand-central-dispatch swift swift3