我的代码有问题,这是我第一次得到它... 我使用Firebase,当我尝试从数据库接收信息并将其插入到我的数组中时,数组未添加信息...
我已经多次使用这种方法,但是每次检查都没发现很多时间后,我却找不到了...
我在数组中添加信息的代码:
func preloadInformation(){
let ref = Database.database().reference()
let ev = ref.child("Lignes").child(RXLigneName)
ev.observe(.childAdded, with: { (snapshot) -> Void in
let Key = snapshot.value as? String
print(Key!)
ref.child("Gare").child(Key!).observeSingleEvent(of: .value) {(snapshot) in
let value = snapshot.value as? NSDictionary
let autoID = value?["Auto_Id"] as? String ?? "000"
let name = value?["Nom"] as? String ?? "⛔️"
let distance = value?[self.RXHowLong ?? "75m" ] as? String ?? "⛔️"
let te = value?["TE"] as? String ?? "⛔️"
let ts = value?["TS"] as? String ?? "⛔️"
let autre = value?["Autre"] as? String ?? "⛔️"
let avl = value?["AVL"] as? String ?? "NIL"
self.userInfo.append(UserInfo(AutoId: autoID, Gare: name, te, ts, autre, distance, avl))
}
})
}
UserInfo类的定义如下:
class UserInfo{
let AutoId: String
let gare: String
let te: String
let ts: String
let autre: String
let ptArret: String
let avl: String
init(AutoId IAID: String, Gare Igare: String, _ Ite: String, _ Its: String, _ Iautre: String, _ IptArret: String, _ Iavl: String) {
self.AutoId = IAID
self.gare = Igare
self.te = Ite
self.ts = Its
self.autre = Iautre
self.ptArret = IptArret
self.avl = Iavl
}}
extension UserInfo: CustomStringConvertible {
var description: String {
var description = ""
description.append("\(AutoId) ,")
description.append("\(gare) ,")
description.append("\(te) ,")
description.append("\(ts) ,")
description.append("\(autre) ,")
description.append("\(ptArret) ,")
description.append("\(avl) ,")
return description
}
}
有关更多信息:
-我一直在尝试在阵列中手动添加一些信息,并且可以正常工作!
-我已经仔细检查了Key
是否不为空但不是!
-我还检查了数据库观察是否成功,但是调试器在数据库中找到了信息...
我不知道该怎么办...
感谢您的帮助!