我正在使用Firebase开发应用程序。
我遇到了一个问题,我不知道如何获取和展示 数据进入表格视图。
这是我的数据库示例:
我的应用程序不知道对象ID。 我想查询特定的“ nomStation”和特定的“ ville” 搜索字符串来自另一个ViewController。
现在,我对此进行了编码,但没有得到我想要的数据:
let ref = Database.database().reference().child("Stations")
ref.observe(.value, with: { snapshot in
for child in snapshot.children {
let childshot = child as! DataSnapshot
let id = childshot.key
let path = "Stations/" + id
ref.queryOrdered(byChild: "nomStation")
.queryEqual(toValue: "AVIA Antony")
.observe(.value, with: { snap in
if let dict = snap.value as? [String: AnyObject] {
self.stationItem!.nomStation = dict["nomStation"] as! String
self.stationItem!.adresse = dict["adresse"] as! String
self.stationItem!.codePostal = dict["codePostal"] as! String
self.stationItem!.ville = dict["ville"] as! String
self.stationItem!.marque = dict["marque"] as! String
self.stationItem!.pays = dict["pays"] as! String
self.stationItem!.commentaire = dict["commentaire"] as! String
self.stationItem!.coordGPS = dict["coordGPS"] as! String
}
})
}
})
谢谢您的帮助。