Can not cast value of type NSTaggedPointerString to NSDictionary

后端 未结 1 1018
醉梦人生
醉梦人生 2021-01-14 06:09

I am trying to assign Firebase values to my struct: var productsArray = [Product]() however I have a little error:

Could not cast value o

相关标签:
1条回答
  • 2021-01-14 06:42

    .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)
        }
    
    0 讨论(0)
提交回复
热议问题