2016-10-13 179 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) 
        }