我试图强制某些函数在使用 Firebase 之前完成从它获取信息。虽然我一直在阅读有关调度组和完成处理的内容,但我不明白为什么仅执行以下操作不起作用:
while (self.expectedPointCount == -1) {
self.ref?.child("Users").child(self.userID!).child("presetRouteCoordinateCount").observeSingleEvent(of: .value, with:{
snapshot in
self.expectedPointCount = snapshot.value as! Int //always zero or greater
})
while(self.expectedPointCount == -1){}
}
这将永远运行。
在 while 循环和 Firebase 快照例程中插入打印语句表明它实际上从未进入 Firebase 快照例程。然而,当它不在 while 循环中时,它确实会进入例程。
看起来我必须以艰难的方式去做,但我就是不明白为什么。
非常感谢!
最佳答案
这将无限循环。尽管 Firebase 调用是在不同的线程上异步执行的,但它永远没有机会启动,因为您永远不会在调用的线程上留下无限 while 循环。
关于ios - Swift 3 中 Firebase 同步性不起作用的解决方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43082532/