且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

无法将类型NSTaggedPointerString的值强制转换为NSDictionary

更新时间:2023-02-04 09:23:11

.childAdded一次提供FIRDataSnapshot ...因此无需为此循环..您只需要在结构中传递当前子级

.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)
    }