I have a list of ids that I want to complete a set of functions for, each id is grabbed from an array and then a group of functions is called in the loop, I have a dispatch queue in the loop, but it seems to run through the loop too fast and before it has finished the functions for an id it has changed the id by looping, thus sending the data from the functions to the wrong places.
The ids need to be the same until all the functions in the loop finish and then start the loop again with new ids.
where am I going wrong?
func sendToDBProject(completion: @escaping (_ finished: Bool) -> ()) {
self.setDate()
for i in artistFinal {
dispatchGroup.enter()
idG = i.key
print("Tony hit artist db send the artist id is \(idG)")
let datesForMessageTemp = artistFinal[idG] as! [String]
datesForMessage = datesForMessageTemp.joined(separator: " - ")
userIDNum = idG
emailAddress.append(userIDNum)
print("Tony the id is userIDNum \(userIDNum)")
self.getMessagesCount(completion: { (complete) in
print("Tony got to end message num artist")
self.getProjects(completion: { (complete) in
print("Tony got to end get projects num artist")
self.sendToDBUserMessage(completion: { (complete) in
print("Tony got to end message snt artist")
self.updateBadgeNum(completion: { (complete) in
print("Tony got messages count")
print("Tony ther status is \(self.statusToSet)")
if self.statusToSet == "Released" {
self.updateUserProjDBRelease(completion: { (complete) in
print("Tony got to end release artist")
self.dispatchGroup.leave()
})
}else if self.statusToSet == "Pencil" {
self.updateUserProjDBPencil(completion: { (complete) in
print("Tony hit end 1 info artist artist db send the artist id is \(self.idG)")
self.dispatchGroup.leave()
})
}else if self.statusToSet == "Book" {
self.updateUserProjDBBook(completion: { (complete) in
print("Tony got to end book artist")
self.dispatchGroup.leave()
})
}
})
})
})
})
}
self.dispatchGroup.notify(queue: DispatchQueue.main, execute: {
print("Tony got to end all artist")
completion(true)
})
}