Firebase query sort order in swift?
<p>When I load the following Firebase Database data into my tableView, the data is sorted in ascending order by date. How can I order this by descending (show the newest post at the top)?</p>

<p>Query in Xcode:</p>

<pre><code>let ref = self.rootRef.child("posts").queryOrderedByChild("date").observeEventType(.ChildAdded, withBlock: { (snapshot) -&gt; Void in
</code></pre>

<p>JSON export:</p>

<pre><code>"posts" : {
    "-KMFYKt7rmfZINetx1hF" : {
      "date" : "07/09/16 12:46 PM",
      "postedBy" : "sJUCytVIWmX7CgmrypqNai8vGBg2",
      "status" : "test"
    },
    "-KMFYZeJmgvmnqZ4OhT_" : {
      "date" : "07/09/16 12:47 PM",
      "postedBy" : "sJUCytVIWmX7CgmrypqNai8vGBg2",
      "status" : "test"
    },
</code></pre>

<p>Thanks!!</p>

<p><strong>EDIT: Below code is the entire solution thanks to Bawpotter</strong></p>

<p><strong>Updated query:</strong></p>

<pre><code>let ref = self.rootRef.child("posts").queryOrderedByChild("date").observeEventType(.ChildAdded, withBlock: { (snapshot) -&gt; Void in

    let post = Post.init(key: snapshot.key, date: snapshot.value!["date"] as! String, postedBy: snapshot.value!["postedBy"] as! String, status: snapshot.value!["status"] as! String)

    self.posts.append(post)

    self.tableView.insertRowsAtIndexPaths([NSIndexPath(forRow: self.posts.count-1, inSection: 0)], withRowAnimation: .Automatic)
</code></pre>

<p><strong>tableView cellForRowAtIndexPath</strong></p>

<pre><code>override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -&gt; UITableViewCell {
        let cell = tableView.dequeueReusableCellWithIdentifier("PostCell", forIndexPath: indexPath) as! PostCell

        self.posts.sortInPlace({$0.date &gt; $1.date})
        self.tableView.reloadData()
</code></pre>

<p><strong>Post.swift:</strong></p>

<pre><code>import UIKit

class Post {
    var key: String
    var date: String
    var postedBy: String
    var status: String

    init(key: String, date: String, postedBy: String, status: String){
        self.key = key
        self.date = date
        self.postedBy = postedBy
        self.status = status
    }
}
</code></pre>