[英]Retrieving key array from Firebase, “variable used within its own value”
嘗試從Firebase獲取子鍵數組
func getWavePosts() {
let wavePostRoot = Database.database().reference().child("waves_posts/\(self.waveLabel!)/")
wavePostRoot.observe(.value , with: {snapshot in
var tempKeys = [String]()
for child in snapshot.children {
let snap = child as! DataSnapshot
let key = snap.key {
tempKeys.append(key as String)
}
}
self.tempNames = tempKeys
})
}
我已經對值進行了此操作,但沒有對鍵進行過操作,附加行是已標記的行。 在鍵初始化下方插入一行將錯誤更改為“無法推斷通用參數'Element'”。 任何幫助將非常感激!
---------不帶for循環編輯---------
let wavePostRoot = Database.database().reference().child("waves_posts/\(self.waveLabel!)/")
wavePostRoot.observe(.value , with: {snapshot in
var tempKeys = [String]()
self.tempNames.append(snapshot.key)
您想進行可選綁定,但是忘記了if
關鍵字。 另外我認為您想檢查snap.key
是否為String
類型
if let string = snap.key as? String {
tempKeys.append(string)
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.