Как я могу заставить свой код ждать завершения задачи в 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.