So I've been trying to put some Firebase data into an array in Swift, so I can then put it into a text field. Everything is working, however, my text view is empty and contains no rows and no data. Does anyone know why this is happening? My code is below (I've imported Firebase and UIKit at the top, don't know why Stack Overflow doesn't let me put that in..sorry about that):
class SummaryEmployeesFeelingViewController: UIViewController, UITableViewDataSource{
struct Feedback {
let id: Int
let feeling: String
let date: Timestamp
}
var feedbackarray = [Feedback]()
@IBOutlet weak var tableView: UITableView!
let summarydb = Firestore.firestore()
override func viewDidLoad() {
super.viewDidLoad()
addDatatoArray()
tableView.dataSource = self
tableView.tableFooterView = UIView()
}
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return feedbackarray.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let feedbackcell = tableView.dequeueReusableCell(withIdentifier: "CellReuseIdentifier")!
let text = feedbackarray[indexPath.row] as? String
feedbackcell.textLabel?.text = text
return feedbackcell
}
func addDatatoArray(){
summarydb.collection("employeefeedback").getDocuments { (snapshot, error) in
if error == nil && snapshot != nil{
for document in snapshot!.documents{
var idValue = document.get("id")
var feelingValue = document.get("feeling")
var dateValue = document.get("date")
let newEntry = Feedback(id: idValue as! Int, feeling: feelingValue as! String, date: dateValue as! Timestamp)
self.feedbackarray.append(newEntry)
}
}
}
}
}
Thank you!