func registerForPostsDeletion()

in FriendlyPix/FPHashTagViewController.swift [54:69]


  func registerForPostsDeletion() {
    let userPostsRef = database.reference(withPath: "hashtags/\(hashtag)")
    userPostsRef.observe(.childRemoved, with: { postSnapshot in
      var index = 0
      for post in self.postSnapshots {
        if post.key == postSnapshot.key {
          self.postSnapshots.remove(at: index)
          self.loadingPostCount -= 1
          self.collectionView?.deleteItems(at: [IndexPath(item: index, section: 0)])
          return
        }
        index += 1
      }
      self.postIds?.removeValue(forKey: postSnapshot.key)
    })
  }