0
我有數據以這種形式火力的我需要顯示設備及其相應的預約我怎麼能解析解析該數據模型class.I是新的模型類解析。 這我已經做了,但我無法在FacilityBooking模型類中解析facilityXXXXXXXX。然後我再次需要在另一個預訂模型類中解析預訂。
struct Facilities_id {
let key: String
var facilities: FacilityBooking
let ref: FIRDatabaseReference
init(snapshot: FIRDataSnapshot) {
key = snapshot.key
ref = snapshot.ref
let snapshotValue = snapshot.value as! [String: AnyObject]
}
}
這是我用於獲取數據的代碼
let ref = FIRDatabase.database().reference(withPath: "facility")
ref.observe(.value, with: { snapshot in
// 2
var facility: [Facilities_id] = []
// 3
for code in snapshot.children {
// 4
let facilityObj = Facilities_id(snapshot: code as! FIRDataSnapshot)
facility.append(facilityObj)
}
// 5
self.facility_id_Arr = facility
print("facitlities ---",self.facility_id_Arr)
})
你在分析新的,但你仍然可以給一個嘗試.. –
我試過,但沒有成功 結構Facilities_id { 讓關鍵:字符串 讓裁判:FIRDatabaseReference 的init(快照:FIRDataSnapshot) {key = snapshot.key ref = snapshot.ref let snapshotValue = snapshot.value as! [String:AnyObject] } } –
@RahulGupta向我們展示您嘗試過的。 –