I am currently trying to develop an application that fetches users data from a firebase database and displays it in a table view. The function that I am having problems with is the function that loads the data.
class DashboardViewController: UIViewController {
@IBOutlet weak var reminderList: UITableView!
var reminders = [EntryViewController]()
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
loadData()
}
func loadData() {
self.reminders.removeAll()
let ref = Database.database().reference()
ref.child("usersEvents").observeSingleEvent(of: .value, with: { (snapshot) in
if let reminderDict = snapshot.value as? [String:AnyObject] {
for (_,reminderElement) in reminderDict {
print(reminderElement);
let reminder = Reminder()
reminders.event = reminderElement["event"] as? String
reminders.dateAndTime = reminderElement["data and time"] as? String
reminders.message = reminderElement["notes"] as? String
self.reminders.append(reminder)
}
}
self.tableView.reloadData() // Should it be inside the if let ?
}, withCancel: { (error) in
print(error.localizedDescription)
})
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.reminders.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if let cell = tableView.dequeueReusableCell(withIdentifier: "ToDoCell") {
var content = cell.defaultContentConfiguration()
content.text = reminders[indexPath.row].event
cell.contentConfiguration = content
return cell
} else {
return UITableViewCell()
}
}
}
}
This is the class thats being developed for the dashboard page of the application. The following error messages are displayed
Value of type '[EntryViewController]' has no member 'event'
Value of type '[EntryViewController]' has no member 'dateAndTime'
Value of type '[EntryViewController]' has no member 'message'
This is where the errors keep appearing
let reminder = Reminder()
reminders.event = reminderElement["event"] as? String
reminders.dateAndTime = reminderElement["data and time"] as? String
reminders.message = reminderElement["notes"] as? String
self.reminders.append(reminder)
}