2016-10-13 149 views
2

我很努力地从我的Firebase获取一些数据。这是结构的样子:Swift3 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的结构中看到的,密钥是一个日期字符串和一个字符串值。

谢谢!

回答

3

好吧,我设法得到的数据。我也将它们添加到结构中。

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) 
        }