Я пытаюсь извлечь данные из firebase для размещения в текстовых представлениях, но код, который я имею, дает мне только один экземпляр всех ключей в «истории».
Я хочу получить данные, если «райдер» равен текущему идентификатору райдера.
Я пробовал разные решения здесь и в Интернете, но, похоже, ничто не помогало мне.
База данных Firebase:
Код, который у меня есть:
let rider = FIRAuth.auth()?.currentUser?.displayName
// getting a reference to the node history
historyRef = ref.child("history")
// retrieve history key from firebase ....
let query = historyRef.queryOrdered(byChild: "rider").queryEqual(toValue: uid)
query.observe(.childAdded) { (snapshot) in
// history auto generated key ............
_ = snapshot.value as? String
let key = snapshot.key
// get values from history and place in outlet
self.historyRef.child(key).observeSingleEvent(of: .value, with: { (snapshot) in
if snapshot.exists() {
var dict = snapshot.value as! [String: AnyObject]
self.price = ((dict["ride_price"] as AnyObject) as! Double)
self.txtPrice1.text = "\(self.price!)" // to make double work in textview
self.txtPrice1.text = "\( Double(round(100 * self.price!)/100) )" // format .xx
self.txtPrice2.text = "\( Double(round(100 * self.price!)/100) )"
self.txtPrice3.text = "\( Double(round(100 * self.price!)/100) )"
self.distance = ((dict["distance"] as AnyObject) as! Double)
self.txtDistance.text = "\(self.distance!)"
self.txtDistance.text = "\( Double(round(100 * self.distance!)/100) )"
self.location = (dict["location"] as! String)
self.txtLocation.text = self.location
self.destination = (dict["destination"] as! String)
self.txtDestination.text = self.destination
self.timestamp = (dict["timestamp"] as! String)
self.txtTimestamp.text = self.timestamp
}
})
}