Removing a dictionary element in Firebase

久未见 提交于 2020-04-30 07:28:26

问题


I am trying to remove a dictionary element in firebase

I want to remove the object :-

D8QmnOSH6vRYiMujKNXngzhdn992: "True" at PendingFriendRequests/RhiZYyMF7STn1vyA27HjnJRsLYb2 so far i have come up with this :-

FIRControllerClass.ref.child("PendingFriendRequests").child(FIRAuth.auth()!.currentUser!.uid).observeSingleEventOfType(.Value, withBlock: {(Snapshot) in

                        let dict = Snapshot.value! as! NSMutableDictionary

                        for each in dict {
                        print(each)

                            print(acceptedFriend)

                            if each.key as! String == acceptedFriend{
                                print(each.key)
                                dict.removeObjectForKey(each.key)
                                print(dict)
                                }
                            FIRControllerClass.ref.child("PendingFriendRequests").child(acceptedFriend).setValue(dict)
                            }
                        })

回答1:


var ref: DatabaseReference!

ref = Database.database().reference()

FIRControllerClass.ref.child("parentKey").child("childKey").setValue(nil)



来源:https://stackoverflow.com/questions/38466994/removing-a-dictionary-element-in-firebase

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!