我正在尝试从Firebase降序获取数据
数据库结构
0G6K7tgHDVXTwPYV5NwhANnWChF2
感觉 -LfP-g3QnO7WmZ3xE8df
currentFeeling: "Angry"
reason: "My phone broke"
timeStamp: 1558435776511
Firebase数据库映像链接 https://user-images.githubusercontent.com/42183565/58200932-5bc15100-7ced-11e9-97f7-6521f229f968.png
这是代码
func getFeelingsDataFromDatabase(){
let ref = Database.database().reference()
let userID = Auth.auth().currentUser?.uid
ref.child("userData").child(userID!).child("feelings").queryOrdered(byChild: "timeStamp").observeSingleEvent(of: .value, with: { (snapshot) in
let value = snapshot.value as? [String:AnyObject]
//print(value)
for data in value!{
let feelingsData = FeelingsIndex()
feelingsData.feelingType = data.value["currentFeeling"] as? String
feelingsData.reason = data.value["reason"] as? String
feelingsData.timeStamp = data.value["timeStamp"] as? Double
self.feelingsList.append(feelingsData)
}
DispatchQueue.main.async {
self.tableView.reloadData()
}
}) { (error) in
print(error.localizedDescription)
}
}
我希望数据根据时间戳进行排列。 我可以过滤数据吗? 每月一次? 每年吗?