2017-04-18 6 views
0

私はFirebaseを使用しています。私のアプリでは、私はbottleIDを渡すことによって子の値を取得し、スナップショットからその値の詳細を取得します。私はMyCollection_Classのオブジェクトに詳細を割り当て、それを配列に追加します。すべての単一のボトルの値を取得した後、テーブルビューを再ロードする前にcreated_atタグを使用してその配列を並べ替える必要があります。特定のインスタンス変数でオブジェクトの配列をソートする方法について私に助言してください。Firebase値でクラスの配列をソート

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() 
     } 
    } 
}) 
+1

あなたは' created_at'のサンプル値を表示することができますので、あなたは私たちに日付 –

+1

が重複する可能性の形式を示す必要があります[プロパティ値でカスタムオブジェクトの配列を並べ替える方法をすばやく](http://stackoverflow.com/questions/24130026/swift-how-to-sort-array-of-custom-objects-by-property-value) –

答えて

0

あなただけ

queryOrderedByChildを使用することにより、既にFirebaseからソートされたデータを取得することができます。

例は次のようになります。それは `STRING`型であるため、

ref.child(bottleID).queryOrderedByChild("created_at").queryEqualToValue(0).observe SingleEventOfType(.Value, withBlock: { snap in 
    print("snap \(snap)") 
    expectation.fulfill() 
}) 
関連する問題