如何按字母顺序对以下数据进行排序?因此,“ deviceRooms1,deviceRooms2,deviceRooms3,...”我希望对数据进行排序。
@objc func fetchRooms()
{
let ref = Database.database().reference().child("0").child("Rooms")
ref.observeSingleEvent(of: .value, with: { (snapshot) in
//let value: NSDictionary = snapshot.value as! NSDictionary
let dic = snapshot.value as! [String:String]
self.tableRowss = Array(dic.values)
self.myTableView.reloadData()
})
}
答案 0 :(得分:2)
您可以尝试
let dic = snapshot.value as! [String:String]
let sortedKeys = Array(dic.keys).sorted(by:<)
self.tableRowss = sortedKeys.map { dic[$0]! }
self.myTableView.reloadData()