firebase按值的类排序阵列



我正在使用firebase。在我的应用程序中,我通过传递瓶装并从快照中获取该值的详细信息来获得子值。然后,我将详细信息分配给MyCollection_Class的对象,然后将其添加到数组中。获得每个瓶子值后,我想在重新加载表视图之前使用created_at标签对数组进行排序。请告知我如何通过特定实例变量对对象的数组进行排序。

let Collection = MyCollection_Class()
FireBaseConstants.AUCTIONS_REF.child(bottleID).observeSingleEvent(of: .value, with: { (snap) in
    if !(snap.value is NSNull) {
        Collection.id = bottle_dict["id"] as? String
        Collection.item_number = bottle_dict["item_number"] as? Int
        Collection.created_at = bottle_dict["created_at"] as? String
        if !(self.MyCollectionsIDArr.contains(Collection.id! as String)) {
             self.MyCollectionsArr.append(Collection)
             self.MyCollectionsIDArr.append(Collection.id!)
             // I want to sort the MyCollectionsArr using created_at here
             self.tbl_Latest.reloadData()
        }
    }
})

您可以通过使用

从firebase中检索已经排序的数据

QueryOrderedByChild。

一个例子是:

ref.child(bottleID).queryOrderedByChild("created_at").queryEqualToValue(0).observe  SingleEventOfType(.Value, withBlock: { snap in
    print("snap (snap)")
    expectation.fulfill()
})

最新更新