ios - 在移动到数组中的下一个项目之前完成项目的功能。iOS
问题描述
我有一个 id 列表,我想为其完成一组函数,每个 id 从一个数组中获取,然后在循环中调用一组函数,我在循环中有一个调度队列,但它似乎在运行通过循环太快,在它完成一个 id 的函数之前,它已经通过循环改变了 id,从而将数据从函数发送到错误的地方。
在循环中的所有函数完成之前,id 必须相同,然后使用新的 id 再次开始循环。
我哪里错了?
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)
})
}
解决方案
推荐阅读
- c# - 从 Azure Keyvault c# 获取带有私钥的 X509 证书
- python - 您能否根据日期时间值是否为“无”进行条件编码?
- reactjs - .map() 迭代的值不会反映在 html 属性中的函数内部
- r - 如何将列从 tibble 转换为 row.names
- javascript - 拖动后防止点击
- python - 从 docker 容器上运行的烧瓶 api 访问本地目录文件
- javascript - 无法绑定到新的构造函数
- c# - 无法创建实例或抽象类型或接口“按钮”XNA/Mono 游戏
- web-services - 为什么性能测试时“孵化率”很重要?
- c - 将文件中的每一行设置为 char*