TableView crashes while adding new item to Firebase

Multi tool use


TableView crashes while adding new item to Firebase
There are many pages of code for this app, so here is the video I recorded it to show you what is going on. Please take a look and then read my question description:
Here is the situation. I'm trying to add a Data Model to Firebase and it is working just fine. And also when I'm fetching all the data it is still OK. But at the moment when I'm adding data and trying to see it the app crashes and it says that there is a nil value. It is definitely not nil, because I see on the real-time database that the data has been successfully posted to Firebase and everything ok with the references. Here is the source code of UITableView
's cellForRowAt
method:
UITableView
cellForRowAt
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! TableViewCell
cell.name.text = myArray[indexPath.row].name
cell.date.text = myArray[indexPath.row].date
if myArray[indexPath.row].raiting == 1 {
cell.raiting.image = UIImage(named: "1")
} else if myArray[indexPath.row].raiting == 2 {
cell.raiting.image = UIImage(named: "2")
} else if myArray[indexPath.row].raiting == 3 {
cell.raiting.image = UIImage(named: "3")
} else if myArray[indexPath.row].raiting == 4 {
cell.raiting.image = UIImage(named: "4")
} else if myArray[indexPath.row].raiting == 5 {
cell.raiting.image = UIImage(named: "5")
}
cell.descriptionTitle.text = myArray[indexPath.row].descriptionTitle
cell.descriptionBody.text = myArray[indexPath.row].description
////
let urlOne = URL(string: myArray[indexPath.row].pictureOne!)
let urlTwo = URL(string: myArray[indexPath.row].pictureTwo!)
let urlThree = URL(string: myArray[indexPath.row].pictureThree!)
URLSession.shared.dataTask(with: urlOne!, completionHandler: { (data, response, error) in
if error == nil {
DispatchQueue.main.async(execute: {
cell.pictureOne.image = UIImage(data: data!)
})
}
}).resume()
//
URLSession.shared.dataTask(with: urlTwo!, completionHandler: { (data, response, error) in
if error == nil {
DispatchQueue.main.async(execute: {
cell.pictureTwo.image = UIImage(data: data!)
})
}
}).resume()
//
URLSession.shared.dataTask(with: urlThree!, completionHandler: { (data, response, error) in
if error == nil {
DispatchQueue.main.async(execute: {
cell.pictureThree.image = UIImage(data: data!)
})
}
}).resume()
return cell
}
Here is my fetch method:
func fetchUsers() {
guard let userID = Auth.auth().currentUser?.uid else { return }
Database.database().reference().child("user").child(userID).observe(.childAdded) { (snapshot) in
if snapshot.value != nil {
let result = snapshot.value as! [String : AnyObject]
self.addingMovie = Model()
self.addingMovie.description = result["body"] as? String
self.addingMovie.date = result["date"] as? String
self.addingMovie.pictureOne = result["imageOne"] as? String
self.addingMovie.pictureTwo = result["imageTwo"] as? String
self.addingMovie.pictureThree = result["imageThree"] as? String
self.addingMovie.name = result["name"] as? String
self.addingMovie.raiting = result["raiting"] as? Int
self.addingMovie.descriptionTitle = result["title"] as? String
print("(self.addingMovie.description) - (self.addingMovie.date) - (self.addingMovie.pictureOne) - (self.addingMovie.pictureTwo)")
print("(self.addingMovie.pictureThree) - (self.addingMovie.name) - (self.addingMovie.raiting) - (self.addingMovie.descriptionTitle)")
self.myArray.append(self.addingMovie)
DispatchQueue.main.async(execute: {
self.tableView.reloadData()
})
}
}
}
Here is my database structure
When I'm launching the app table view successfully fetches all the data
@Sh_Khan the line is right after the //// let urlOne = URL(string: myArray[indexPath.row].pictureOne!)
– Tigran
yesterday
where you parse that array and what database structure & keys
– Sh_Khan
yesterday
@Sh_Khan added to the post
– Tigran
yesterday
These values are printed inside the the callback ??
– Sh_Khan
yesterday
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
video issues , can you please point to the line ??
– Sh_Khan
yesterday