The question is little bit unclear but if you want to populate a tableView you will need to get the data from Firebase, populate an array (the dataSource), and reload the tableView.
First off we need to set up an .ChildAdded observer to load the data into the messagesArray, which is used as the tableView datasource
class AppDelegate: NSObject, NSApplicationDelegate {
var messagesArray = [[String:String]]() //an array of dicts, tableView datasource
var initialLoad = true
and the code to load the data initially and then watch for added messages
messagesRef.observeEventType(.ChildAdded, withBlock: { snapshot in
let dict = [String: String]()
dict["date"] = snapshot.value("date")
dict["msg"] = snapshot.value("message")
dict["sender"] = snapshot.value("sender")
self.messagesArray.append(dict)
if ( self.initialLoad == false ) { //upon first load, don't reload the tableView until all children are loaded
self.itemsTableView.reloadData()
}
})
then - and this is the cool part...
//this .Value event will fire AFTER the child added events to reload the tableView
// the first time and to set subsequent childAdded events to load after each child
// is added in the future
messagesRef.observeSingleEventOfType(.Value, withBlock: { snapshot in
print("inital data loaded so reload tableView! \(snapshot.childrenCount)")
self.messagesTableView.reloadData()
self.initialLoad = false
})
With the above code, the order of the data is by their key - and if those keys were generated by Firebase, they will be sequential in the order the messages were created.
Your tableView is then populated from the messagesArray, and you can pick off the date, message and sender to put into the tableView columns or however you want the populate your cellView.
Your other requirement was to have them ordered by Date, descending. That's a super great question and had has answer here - it was a two part question but you'll see the thought process.
In Firebase, how can I query the most recent 10 child nodes?
you will also want to leverage Firebases query capabilities to get the specific data you want instead of the general data from above...
messagesRef.queryOrderedByChild("date").observeEventType(.ChildAdded, withBlock: {
snapshot in
//create a dict from the snapshot and add to tableview
})