Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.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
如何将Firebase Swift 3模棱两可的引用传递给成员';观察(用)和#x27;错误?_Firebase_Firebase Realtime Database_Swift3 - Fatal编程技术网

如何将Firebase Swift 3模棱两可的引用传递给成员';观察(用)和#x27;错误?

如何将Firebase Swift 3模棱两可的引用传递给成员';观察(用)和#x27;错误?,firebase,firebase-realtime-database,swift3,Firebase,Firebase Realtime Database,Swift3,我知道过去有人问过这个问题,但我无法找到一个适用于swift 3的解决方案。谁能给我指一下正确的方向吗。这是我的密码: ref.child(uid).child("flights").observe(.value, with:{ (snapshot: FIRDataSnapshot!) -> Void in self.messages.append(snapshot) let row = [IndexPath(row: self.messages

我知道过去有人问过这个问题,但我无法找到一个适用于swift 3的解决方案。谁能给我指一下正确的方向吗。这是我的密码:

    ref.child(uid).child("flights").observe(.value, with:{  (snapshot: FIRDataSnapshot!) -> Void in
        self.messages.append(snapshot)

        let row = [IndexPath(row: self.messages.count-1, section: 0) ]


        print(snapshot)

        self.flightTableView.insertRows(at: row, with: .automatic)

        DispatchQueue.main.async {
            self.flightTableView.reloadData()
        }
    })

}

我把代码分解成两个语句,它开始工作了

    let child:FIRDatabaseReference = ref.child(uid).child("flights")


    child.observe(.childAdded) { (snapshot:FIRDataSnapshot) in
        print(snapshot)
    }

我把代码分解成两个语句,它开始工作了

    let child:FIRDatabaseReference = ref.child(uid).child("flights")


    child.observe(.childAdded) { (snapshot:FIRDataSnapshot) in
        print(snapshot)
    }

Swift 3和Firebase 3.17.0

这样就可以了,试试下面的代码

        let ref = FIRDatabase.database().reference().child("uid").child("flights")
        ref.observe(.value, with: { (snapshot) in
            print("Success get the snapshot \(snapshot)")
            // do something with snapshot than
            DispatchQueue.main.async {
                self.yourTableView.reloadData()
            }
        }) { (error) in
            print("Failed get the snapshot \(error.localizedDescription)")
            // do something to handle error
        }

Swift 3和Firebase 3.17.0

这样就可以了,试试下面的代码

        let ref = FIRDatabase.database().reference().child("uid").child("flights")
        ref.observe(.value, with: { (snapshot) in
            print("Success get the snapshot \(snapshot)")
            // do something with snapshot than
            DispatchQueue.main.async {
                self.yourTableView.reloadData()
            }
        }) { (error) in
            print("Failed get the snapshot \(error.localizedDescription)")
            // do something to handle error
        }