0

i am retrieving data from firebase and i have few buttons to filter the data. this function is working but for see the filtered results i have to exit and reopen the app. here is my code:

self.ItemRef.observe(.value, with: { (snapshot) in
   var updatedItem = [MyItem]()
   for user_child in (snapshot.children) {
                    
       let user_snap = user_child as! DataSnapshot
       let dict = user_snap.value as! [String: Any]
    
       guard let category = dict["category"] as? String else { return}
       var item =  MyItem.init(image1: ItemImage1, image2: "", image3: "",
                               image4: "", image5: "", name: ItemName,
                               details: "", size: "", price: price,
                               gender: "", category: category)
      if item.category == filteredCategory {
         updatedItem.append(item)
      }
   }
   self.itemList = updatedItem
 })
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
adirbuilder
  • 101
  • 1
  • 12
  • The code is missing the closing bracket on the closure – flanker Feb 07 '21 at 17:45
  • thanks! I've updated my question @flanker do u know how to help me solving my issue ? – adirbuilder Feb 07 '21 at 17:46
  • Not being a Firebase user I'm guessing the above if triggered on startup or on a change in the observed data? And It's referencing a value `filterCategory` that is set somehow by clicking a button? – flanker Feb 07 '21 at 19:47
  • After updating the data in `itemList`, you'll need to tell iOS to repaint the view(s) that show that data. If you're using classic UI, that'd be a call to something like `reloadData()` as shown here: https://stackoverflow.com/questions/37146801/how-to-update-data-in-tableview-swift. SwiftUI probably has another method to accomplush the same. – Frank van Puffelen Feb 07 '21 at 19:52

0 Answers0