我的 Firebase 数据库
更具体地说,我随机生成了子项(列表),我想从这些随机生成的列表中获取键的字符串值。
例如,如果我想要图片 URL 地址,我想获取键“PhotoURL:”的字符串值。
提前致谢!
最佳答案
首先您需要做的是import Firebase
然后从数据库类中调用一个函数,如下所示:
let ref = Database.database().reference().child("Listings")
你可以递归地调用 child 来深入你的树
//.child("Listings").child("SomeListing").child("PhotoURL")
然后调用 observeSingleEvent 从 firebase 接收值。 您的值存储在快照变量中
ref.observeSingleEvent(of: .value, with: { (snapshot) in
guard let listingsDictionary = snapshot.value as? [String: Any] else { return }
listngsDictionary.forEach({ (key, value) in
// Here you can iterate through it
})
}) { (err) in
print("Failed to fetch following listings:", err)
}
关于swift - 如何使用 Swift 4 从 firebase 中的 child 那里获取特定值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53514553/