I am having a problem removing a kid string from an array of other aid strings in firebase. When a user creates a group chat, they include sharers. Those sharers are added to an array of strings and then added to firebase when made. Now when a user clicks the leave group chat button, I can't figure out a way to remove the current user's user id from that array, in which I have already checked if their uid is in the array. I have tried everything I can guys, first I tried ref.child("Group Chats").child(groupKey).child("sharers").child(myriad).removeValue, and that did not work, I also tried creating a new array without the current users id, removing the old array and adding the new one to firebase, all did not work, now I turn to some fellow coders. How can I remove the current users did from an array of uids in firebase.
let action = UIAlertAction(title: "Leave Group Chat", style: .default, handler: {( alert : UIAlertAction) -> Void in
let ref = FIRDatabase.database().reference()
if let keyp = self.groupChats[indexPath.row].key {
ref.child("Group Chats").child(keyp).child("sharers").child(uip).removeValue()
}
self.groupChat.removeAll()
self.pull()
self.pullFromSharers()
self.tableViewManage.reloadData()
})

Thank you!
After discussion with OP, we have found the solution
Problem is that your path is not calculated correctly, your path was getting the value instead of child, so modify your code as follows:
ref.child("Group Chats").child(keyp).child("sharers").observe(.value, with: { snapshot in
if let sharers = snapshot.value as? [String] {
for i in 0..<sharers.count {
if sharers[i] == uip {
ref.child("Group Chats").child(keyp).child("sharers").child("\(i)").removeValue()
}
}
}
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With