I want to run a couple of asynchronous tasks and get a notification after all of them are finished. The tasks should be run concurrently. Is what i'm doing correct? because it calls the notification immediately and does not wait for task to finish:
let dispatchGroup = DispatchGroup()
let queue = DispatchQueue(label: "com.name.group", attributes: .concurrent)
queue.async(group: dispatchGroup) {
self.asyncFunc1() { (data) in
// returns something
}
}
queue.async(group: dispatchGroup) {
self.asyncFunc2() { (data) in
// returns something
}
}
queue.async(group: dispatchGroup) {
self.asyncFunc3() { (data) in
// returns something
}
}
dispatchGroup.notify(queue: queue) {
DispatchQueue.main.async {
// Update the UI
}
}
Should not dispatchGroup.notify() get fired after all three calls are done?