How to display the below data in a view:
[
"parties" {
"2016-12-30" {
"uid" {
"name": "joe",
"age": "32"
},
"uid" {
"name": "kevin",
"age": "29"
}
},
"2016-12-25" {
"uid" {
"name": "ben"
"age": "44"
}
}
}
]
In my controller I have
var parties = [Party]()
DataService.ds.REF_PARTIES.observe(.value, with: { (snapshot) in
if let snapshot = snapshot.children.allObjects as? [FIRDataSnapshot] {
print(snapshot)
for snap in snapshot {
if let partyDict = snap.value as? [String: AnyObject] {
let key = snap.key // the party date
let party = Party(date: key, partyData: partyDict)
self.parties.append(party)
}
}
}
self.tableView.reloadData()
})
class PartyFeedCell: UITableViewCell:
func configureCell(party: Party) {
dateLabel.text = part.date // date as expected
}
In react, I could use Object.key to go deeper in the loop and get the users for those dates (keys). Any way to accomplish this? Under, say xxx date, I should see a list of users.
Party.swift:
import Foundation
class Party {
private var _name: String!
private var _age: String!
var name: String {
return _name
}
[...]
init(name: String, age: String) {
self._name = name
self._age = age
}
init(date: String, partyData: [String: AnyObject]) {
self._date = date
[...]
}
}
DataService.swift:
import Foundation
import FirebaseDatabase
let DB_BASE = FIRDatabase.database().reference()
class DataService {
static let ds = DataService()
private var _REF_BASE = DB_BASE
private var _REF_PARTIES = DB_BASE.child("parties").queryOrderedByKey()
var REF_BASE: FIRDatabaseReference {
return _REF_BASE
}
var REF_PARTIES: FIRDatabaseQuery {
return _REF_PARTIES
}
}