因此,我目前正在研究像snapchat這樣的克隆,並且我正在向服務器發送拉請求,但是對於下載,它不太好。我創建了一個參考看起來像這樣的數據庫,Swift中的FirebaseDatabase查詢問題
var recievers: FIRDatabaseReference{
return mainRef.child("pullRequests")
}
,然後我有一個分析數據(我知道是不是去了解這一點的最好方式的viewController,但我只是想得到它現在的工作),並在那裏我有這個
DataService.instance.recievers.observeSingleEvent(of: .value) {(recipients: FIRDataSnapshot) in
if let recipient = recipients.value as? Dictionary<String,AnyObject>{
var index = 0;
for(key,value) in recipient{
index = index+1
if let dict = value as? Dictionary<String,AnyObject>{
if let reciever = dict["recipents"] as? Dictionary<String,AnyObject>{
if let num = reciever["\(index)"] as? String{
let uid = num
recipientsArr.append(uid)
}
}
}
}
}
}
for i in 0...recipientsArr.count{
print(i)
}
我沒有得到任何編譯錯誤,但它也沒有添加任何進入recipientsArr,任何人都可以幫助指導我在正確的方向?
我的火力地堡看起來是這樣的:
我試圖閱讀只有recipents元素「tLvt ...」,「JqIr ..」等放在recipientsArr,我也試過你的方法,它導致了相同的結果。看起來好像什麼都沒有被添加到數組 – andrewF
你有沒有運行調試器來查看快照解碼失敗的位置?只是爲了確保 - ObserveSingleEvent的回調函數甚至調用了嗎?如果你想讀取收件人列表的變化,最好選擇這個作爲你的參考:mainRef.child(「pullRequests」)。child(「recipents」 ) –