title: Remove value from firebase dictionary with swift, filter on client side blocked users
body: <p>My database structure is like this; </p>
  
  <pre><code> "blockByUser" : {
    "pcAkkvLY1TYseqk04sISUqop3Wt1" : {
      "7OYw2AtvZ7hxprFiX2e1LOn1DWs2" : true,
      "W4uaW1pOtkYUMh1jTJJVXQu0u6f1" : true
    }
   }
  
  "users" : {
     "Gn0SwQOmUvNkAFeg0YpGax75cpz2" : {
       "blocked" : {
         "pcAkkvLY1TYseqk04sISUqop3Wt1" : true
       },
       "capacity" : "NO",
       "country" : "Netherlands",
       "email" : "katnl"
     },
     "iDlNUNNAsiN0JmO8bEdYAdANcn62" : {
       "blocked" : {
         "Gn0SwQOmUvNkAFeg0YpGax75cpz2" : true
       },
       "capacity" : "NO",
       "country" : "Netherlands",
       "email" : "dal"
     },
     "pcAkkvLY1TYseqk04sISUqop3Wt1" : {
       "capacity" : "NO",
       "country" : "Netherlands",
       "email" : "test",
     }
   }
  </code></pre>
  
  <p>I'm now I have to filter on the client side, remove the keys from blockedByUser so I have 2 dictionaries one the 'complete' list of users and one blockedByUsers, now I run into problems to update my collectionView, because the firebase data is async and I'm not sure how to make this working like this:</p>
  
  <pre><code>func fetchBlockedUsers() {
  
          print("Fetching blocked users..")
  
          let ref = FIRDatabase.database().reference().child("blockedByUser").child(currentUserUID)
          ref.observe(.value, with: { (snapshot) in
              guard let dictionaries = snapshot.value as? [String: Any] else { return }
  
              self.users.removeAll()
  
              let blocked = dictionaries
  
              let ref = FIRDatabase.database().reference().child("users")
              ref.observeSingleEvent(of: .value, with: { (snapshot) in
                  guard let dictionaries = snapshot.value as? [String: Any] else { return }
  
                  var dict = dictionaries
                  for block in blocked {
                      dict.removeValue(forKey: block.key)
                  }
  
  
                  dict.forEach({ (key, value) in
                      guard let userDictionary = value as? [String: Any] else { return }
  
                      let user = UserModel(uid: key, dictionary: userDictionary)
                      self.users.append(user)
                  })
  
                  self.collectionView?.reloadData()
  
              }) { (err) in
                  print("Failed to fetch users for search:", err)
              }
  
          }) { (err) in
              print("Failed to fetch users for search:", err)
          }
  
      }
  </code></pre>
  
  <p>But maybe it's better to fan-out the data and use firebase functions to manage the data? </p>