I want to send requests one after the other. Wait for the response from the first to send the second.
Currently I use this:
DispatchQueue.global().async {
let dispatchGroup = DispatchGroup()
dispatchGroup.enter()
self.requestOne { _ in
dispatchGroup.leave()
}
dispatchGroup.wait()
dispatchGroup.enter()
self.requestTwo { _ in
dispatchGroup.leave()
}
dispatchGroup.wait()
dispatchGroup.enter()
self.requestTree { _, url in
user.profileImage = url?.absoluteString
dispatchGroup.leave()
}
dispatchGroup.wait()
self.requestFour { error in
completion(error)
}
}
It works very well but I wanted to know if there is a way to make this cleaner, swiftier without using
dispatchGroup.enter()
dispatchGroup.leave()
dispatchGroup.wait()
Even a pattern to wrap logic in a class