func updatePost()

in FriendlyPix/FPFeedViewController.swift [535:552]


  func updatePost(_ post: FPPost, postSnapshot: DataSnapshot) {
    let postId = postSnapshot.key
    commentsRef.child(postId).observeSingleEvent(of: .value, with: { commentsSnapshot in
      var commentsArray = [FPComment]()
      let enumerator = commentsSnapshot.children
      while let commentSnapshot = enumerator.nextObject() as? DataSnapshot {
        let comment = FPComment(snapshot: commentSnapshot)
        commentsArray.append(comment)
      }
      if post.comments != commentsArray {
        post.comments = commentsArray
        if let index = self.posts.firstIndex(where: {$0.postID == post.postID}) {
          self.collectionView?.reloadItems(at: [IndexPath(item: index, section: 0)])
          self.collectionViewLayout.invalidateLayout()
        }
      }
    })
  }