0

Currently my database looks like this:

<posts>
 - "1"
 - "2"
 - "3"

And that is also the order I'm retrieving and ordering this data to my iOS app using:

func getQuery() -> FIRDatabaseQuery {
    let myTopPostsQuery = (ref.child("posts"))

    return myTopPostsQuery
}

override func viewDidLoad() {
    super.viewDidLoad()


    self.ref = FIRDatabase.database().reference()

    dataSource = FirebaseTableViewDataSource.init(query: getQuery(),prototypeReuseIdentifier: "Cellident", view: self.tableView)


    dataSource?.populateCellWithBlock { (cell: UITableViewCell, obj: NSObject) -> Void in

        let customCell = cell as! CustomCellTableViewCell
        let snap = obj as! FIRDataSnapshot
        let childString = snap.value as! [String : AnyObject]

        customCell.textLabel.text = String(childString)}

    } 

   tableView.dataSource = dataSource
   tableView.delegate = self

}

And then obviously it gets displayed in the table from 1 to 3 in that same order. What I want to achieve is displaying it in the reversed order, such that the last element in the database gets displayed first, namely 3, 2 and then 1 as the last (furthest down) element in the table.

Haven't found anything in the docs about that yet, it's mostly about ordering it by a value. I guess that either I can let firebase retrieve it in a different order or populate the table cells reversed?

ffritz
  • 2,180
  • 1
  • 28
  • 64
  • 1
    You'll either need to reverse them client-side or add a property with an inverted value to the data. See http://stackoverflow.com/questions/38681011/firebase-querying-in-reverse-order – Frank van Puffelen Aug 13 '16 at 14:41
  • @FrankvanPuffelen Thank you, that approach is now what I used, and it works. – ffritz Aug 14 '16 at 12:24

0 Answers0