Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios Swift 3中Firebase同步性的解决方法不工作_Ios_Swift_Asynchronous_Firebase_Firebase Realtime Database - Fatal编程技术网

Ios Swift 3中Firebase同步性的解决方法不工作

Ios Swift 3中Firebase同步性的解决方法不工作,ios,swift,asynchronous,firebase,firebase-realtime-database,Ios,Swift,Asynchronous,Firebase,Firebase Realtime Database,我试图强制一些函数在使用Firebase之前完成从Firebase获取信息。虽然我一直在阅读调度组和完工处理方面的内容,但我不明白为什么仅仅做以下工作不起作用: while (self.expectedPointCount == -1) { self.ref?.child("Users").child(self.userID!).child("presetRouteCoordinateCount").observeSingleEvent(of: .value, with:{

我试图强制一些函数在使用Firebase之前完成从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快照例程中插入print语句表明它实际上从未进入Firebase快照例程。但是,当它不在while循环中时,它确实会进入例程

看起来我不得不用艰难的方式去做,但我不明白为什么


多谢各位

这将导致无限循环。尽管Firebase调用是在不同的线程上异步执行的,但它永远不会有机会启动,因为您永远不会离开调用线程上的无限while循环