I have attached a screen shot of what my data looks like. I am trying to get the list of titles (child node) and populate my table field with same list.
My errors and explanation are highlighted below in the code.
Appreciate any help.
//Set the Firebase Reference
var ref = Database.database().reference()
var searchJSONQuery : String = ""
var jobsData = [String]()
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return jobsData.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "PostCell")
cell?.textLabel?.text = jobsData[indexPath.row]
return cell!
}
func retrieveJobTitles(){
let positionRef = ref.child("positions")
positionRef.observeSingleEvent(of: .value, with: { (snapshot) in
// Iterate through all of your positions
for child in snapshot.children {
let positionsInfo = child.value as! [String: Any]
Error --> Value of type 'Any' has no member 'value'
Cast 'Any' to 'AnyObject' or use 'as!' to force downcast to a more specific type to access members
When I use AnyObject as the error message suggests I just run into another one .. Value of type 'Any' has no member 'value'
let jobTitle = positionsInfo["title"] as! String
if jobTitle != nil {
self.jobsData.append(jobTitle)
}
}
self.jobPostsTableView.reloadData()
})
}