Mar*_*ode 3 grand-central-dispatch firebase swift swift3
我正在尝试让我的应用程序使用调度组来确保在继续之前已发送所有邀请.我认为notify只有在enters匹配后才会调用回调,leave但我的多次调用似乎是多次调用,这是我的代码:
for invite in invites {
dispatchGroup.enter()
let ref = FIRDatabase.database().reference().child("users").child(invite.id).child("invites")
print(invite)
ref.updateChildValues([name: nameTextField.text!]) { (error, ref) -> Void in
dispatchGroup.leave()
dispatchGroup.notify(queue: DispatchQueue.main, execute: {
print("YOYOYO")
})
}
}
Run Code Online (Sandbox Code Playgroud)
在我的控制台中,我看到2个"YOYOYO"让我很困惑.任何人都可以告诉我,如果我这样做不正确或者我的假设是错误的吗?
你可能有两个invites.移动dispatchGroup.notify出的for循环,如果你希望所有后得到通知invites进行处理:
for invite in invites {
dispatchGroup.enter()
let ref = FIRDatabase.database().reference().child("users").child(invite.id).child("invites")
print(invite)
ref.updateChildValues([name: nameTextField.text!]) { (error, ref) -> Void in
dispatchGroup.leave()
}
}
dispatchGroup.notify(queue: DispatchQueue.main) {
print("YOYOYO")
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
980 次 |
| 最近记录: |