ios - Swift3 Firebase 检索数据

标签 ios swift firebase firebase-realtime-database

我正在努力从 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/

相关文章:

ios - 使用 SecItemCopyMatching swift 2.0 导出由 SecKeyGeneratePair 生成的公钥

iphone - uitableview 每行显示 3 个对象

ios - UITextField - 只允许数字和标点符号输入/键盘

swift - 在 Swift 中将字典值转换为不同的类型

ios - StackView 高度 Swift

ios - NumberKeyPad 中的完成按钮导致 iOS 8 出现问题

ios - 如何在 IAP Swift 中获取正确的原始购买日期和过期日期

javascript - 页面并不总是识别带有 ES6 promise 的 ng-if/new $scope 变量

android - Android 中 Google AdMobs 和 Firebase 分析的 Multi Dex 问题

android - 如何访问firebase中的相​​关数据