Data from Firebase is not appearing in my TableView.

For some reason, the data from my FirebaseDatabase is not showing up in my TableView. I've done the "tableView.delegate and tableView.datasource = self", I've registered the "cell". I've even added tested mock arrays like "var postData: [String] = ["delivery", "fun"]" and they have showed up in my tableView. Any idea what I am doing wrong?


import UIKit
import Firebase
import FirebaseDatabase




class NewConversationViewController: UITableViewController {
   
  var ref: DatabaseReference!
   
  var userData = [String]()
   
  override func viewDidLoad() {
    super.viewDidLoad()
     
    self.tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
     
    ref = Database.database().reference()
     
    ref.child("users\("name")").observeSingleEvent(of: .childAdded) { (snapshot) in
       
      let user = snapshot.value as? String
       
      if let actualUsers = user {
        self.userData.append(actualUsers)
         
        DispatchQueue.main.async {
          self.tableView.reloadData()
        }
      }
    }
     
     
     
  }
   
   
   
  override func tableView( tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return userData.count
  }
   
  override func tableView(
tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
    cell.textLabel?.text = userData[indexPath.row]
     
    return cell
  }

}


Suggest you contact the authors of any 3rd party products directly, vs. expecting that support here. devForums is Apple IDE-centric.

Good luck.
You should format your code with the code formatter tool (<>)

Code Block
import UIKit
import Firebase
import FirebaseDatabase
class NewConversationViewController: UITableViewController {
var ref: DatabaseReference!
var userData = [String]()
override func viewDidLoad() {
super.viewDidLoad()
self.tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
ref = Database.database().reference()
ref.child("users\("name")").observeSingleEvent(of: .childAdded) { (snapshot) in
let user = snapshot.value as? String
if let actualUsers = user {
self.userData.append(actualUsers)
DispatchQueue.main.async {
self.tableView.reloadData()
}
}
}
}
override func tableView( tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return userData.count
}
override func tableView( tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
cell.textLabel?.text = userData[indexPath.row]
return cell
}
}


Have you tested user for nil on line 18 ?
Add the following on line 19
print("user is", user).
I suspect you get nil, which would mean you don't get correct content in snapshot, or that this content is not yet loaded when you try to use it).
Data from Firebase is not appearing in my TableView.
 
 
Q