I am trying to assign Firebase values to my struct: var productsArray = [Product]()
however I have a little error:
Could not cast value o
.childAdded
gives FIRDataSnapshot
at a time ... so no need to loop for this .. you just need to pass the current child in your structure.
self.productsArray.removeAll()
var newPostsArray = [Product]()
let ref = FIRDatabase.database().reference().child("Snuses").queryOrdered(byChild: "Brand").queryEqual(toValue: brandName)
ref.observe(FIRDataEventType.childAdded, with: { (posts) in
let newPost = Product(snapshot: posts as! FIRDataSnapshot)
newPostsArray.insert(newPost, at: 0)
self.productsArray = newPostsArray
self.tableView.reloadData()
}) { (error) in
print(error.localizedDescription)
}