如何将Firebase Swift 3模棱两可的引用传递给成员';观察(用)和#x27;错误?
我知道过去有人问过这个问题,但我无法找到一个适用于swift 3的解决方案。谁能给我指一下正确的方向吗。这是我的密码:如何将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
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
}