I've got a function with a completion handler, and in within the function Im' making 2 separate async calls.
The pseudo for it is like :
func Foo(completion: ()->()) {
let dispatchGroup = DispatchGroup()
for doc in documents {
dispatchGroup.enter()
ref.getDocument(completion: { (snapshot, error) in
//Need another getDocument call here
let Object = Object(init with snapshot data)
dispatchGroup.leave()
}
}
} completion()
What I need to do is add another async call where I've added a comment.
That would make the code look like :
ref.getDocument(completion: { (snapshot, error) in
userCountRef.getDocuments(completion: { (snap, error) in
let Object = Object(init with snapshot data)
dispatchGroup.leave()
}
} completion()
The problem with the 2nd set of code is that my completion handler gets called after the first go through of my for loop.
Basically what I am looking to do is to be able to handle two sets of async calls with a dispatch group. I need the first call to go off, and then with the information with the first call I need to use that to make a second call, then at the end make a class object, loop through completely rinsing and repeating, and then at the very end call my completion.
How can this be accomplished?