0

When a user taps a button I want to be able to delete 2 values in separate parent nodes using a single call. At the moment, I've just placed the 2nd database delete call within the completion block of the 1st call.

 guard let uid = Auth.auth().currentUser?.uid else {return}
    guard let convoId = conversation?.conversationId else {return}
    let ref = Database.database().reference()

    let leaveChatAction = UIAlertAction(title: "Leave", style: .destructive) { (action) in
        ref.child("users").child(uid).child("conversations").child(convoId).removeValue(completionBlock: { (error, ref) in

            if let error = error {
                print ("Couldn't delete convo ID from users node:", error)
            }

            ref.child("conversation_users").child(convoId).child(uid).removeValue(completionBlock: { (error, ref) in

                if let error = error {
                    print ("Couldn't delete userID from convo node:", error)
                }

                self.navigationController?.popViewController(animated: true)

            })
        })
    }
Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
Eric
  • 199
  • 1
  • 11
  • You could try a multi location update to make several changes all at once: https://firebase.googleblog.com/2015/09/introducing-multi-location-updates-and_86.html – Doug Stevenson Sep 05 '18 at 21:38
  • If I understand the question correctly, I'm pretty sure this was a duplicate of an already asked question. If not, clarify the question. – Jay Sep 06 '18 at 17:18

0 Answers0