I seem to have encountered an error with fetching data from Firebase.
My goal is to observe the jobs collection for any live updates, and the code below throws an error:
func fetchJobs() {
ref.child("jobposts").observe(.value) { (snapshot) in
guard let dictionary = snapshot.value as? [String:AnyObject] else { return}
var job = JobData()
job.title = (dictionary["title"] as! String) <-- Error Here
job.company = (dictionary["company"] as! String)
job.city = (dictionary["city"] as! String)
job.salary = (dictionary["salary"] as! String)
job.creator = (dictionary["creator"] as! String)
self.jobs.append(job)
}
}
Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value
The weird thing is, that this worked before and i'm not sure what happened, im just starting to understand SwiftUI after all :D
My Firebase database looks like this:
Thanks in advance for all the suggestions and possible solutions! <3
EDIT: Result from print(dictionary):
["-MkmZtye53DPpWb0-Wsn": {
city = 123;
company = 123;
creator = 8NHEiFMaCdSlEsBwuBw5oWrArOh1;
salary = Test;
title = 123;
}]