how to work with dispatchgroup in swift code example
Example: DispatchGroup example swift
class DispatchGroupExample: UIViewController {
private let dispatchGroup = DispatchGroup()
override func viewDidLoad() {
super.viewDidLoad()
fetchData(url: xxx)
fetchData(url: yyy)
dispatchGroup.notify(queue: .main) {
self.goToNext()
}
}
private func fetchData(url: URL) {
dispatchGroup.enter()
URLSession.shared.dataTask(with: url) {
[weak self] (data, urlResponse, error) in
...
self?.dispatchGroup.leave()
}
}
}