【发布时间】:2019-08-09 18:40:37
【问题描述】:
我正在尝试从我的 firebase 数据库中获取数据,这样我就可以将其存储在一种字典形式中,该字典类型是 [String: [Any]] 类型,其中键是唯一 ID,值是一种数组,其数据存储在 uniqueID->Question 下。
func getData(currUser: String, completion: @escaping (([String : [Any]]) -> ())) {
var newArray = [String : [Any]]()
let ref = Database.database().reference(fromURL: "MYURL").child("users/\(currUser)/Questions").observeSingleEvent(of: .value, with: { (snap) in
let enumerator = snap.children
while let rest = enumerator.nextObject() as? DataSnapshot, let value = rest.value{
newArray.updateValue([value], forKey: rest.key)
}
completion(newArray)
})
}
这个完成块给了我:
["-LlpbizBpQTXOQ6zv0zd": [{ 问题 = ( 你好, 测试, 呸呸呸呸 ); }]]]
相反,我怎样才能得到
[“-LlpbizBpQTXOQ6zv0zd”:[你好,测试,kkkkkkkkkkkk]]
【问题讨论】:
标签: swift firebase dictionary firebase-realtime-database