gpt4 book ai didi

ios - Swift3 Firebase 检索数据

转载 作者:可可西里 更新时间:2023-11-01 00:58:15 25 4
gpt4 key购买 nike

我正在努力从我的 Firebase 获取一些数据。这是结构的样子:

enter image description here

这是我用来检索数据的代码:

var followDatesDict = [String:String]()

databaseRef.child("FollowGroups").child(selectedFollowGroupId as String).observeSingleEvent(of: .value, with: { (snapshot) in
if snapshot.hasChildren(){

let name = snapshot.childSnapshot(forPath: "followgroupTitle").value as! String
let sDate = snapshot.childSnapshot(forPath: "startDate").value as! String
let eDate = snapshot.childSnapshot(forPath: "endDate").value as! String

followDatesDict = snapshot.childSnapshot(forPath: "followDates")......



}
})

我可以很好地检索 namesDateeDate。但是有谁知道如何填写按日期排序的 followDatesDict 吗?正如您在 followDates 的结构中所见,键是一个日期字符串和一个字符串值。

谢谢!

最佳答案

好的,我设法获取了数据。我还将它们添加到结构中。

let enumerator = snapshot.childSnapshot(forPath: "followDates").children
while let rest = enumerator.nextObject() as? FIRDataSnapshot {
let key_followDate = rest.key
let value_UserId = rest.value as! String

//add to dictionary
self.followDatesDict.insert(followgroupOverview(followDate:key_followDate, followUserId:value_UserId), at: 0)
}

关于ios - Swift3 Firebase 检索数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40025842/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com