Lets say i have an array of strings, and i call an async method that returns an int from it. I want to know when i have those int values in my array of ints.
Don't wait. Get notified with DispatchGroup
.
let rndStrings = ["a", "b", "c"]
let group = DispatchGroup()
var rndInts = [Int]()
rndStrings.forEach { rndString in
group.enter()
someAsyncMethod { intResult in
rndInts.append(intResult)
group.leave()
}
}
group.notify(queue: DispatchQueue.main) {
print("finished")
}