Created
February 7, 2022 14:55
-
-
Save LovaRK/a8c5ede17dfa729287d3011fbd10ec8c to your computer and use it in GitHub Desktop.
How to do two concurrent API calls in swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func downloadDetails(){ | |
let dispatchGroup = DispatchGroup() | |
dispatchGroup.enter() // <<--- | |
WebServiceManager.getAData(format:A, withCompletion: {(data: Any? , error: Error?) -> Void in | |
if let success = data { | |
DispatchQueue.main.async { | |
(success code) | |
dispatchGroup.leave() // <<---- | |
} | |
} | |
}) | |
dispatchGroup.enter() // <<--- | |
webServiceManager.getBData(format: B, withCompletion: {(data: Any? , error: Error?) -> Void in | |
if let success = data { | |
DispatchQueue.main.async { | |
(success code) | |
dispatchGroup.leave() // <<---- | |
} | |
} | |
}) | |
dispatchGroup.notify(queue: .main) { | |
// whatever you want to do when both are done | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment