从firebase dashbord中删除整个节点

时间:2016-09-03 20:48:16

标签: swift firebase firebase-realtime-database lldb removechild

我尝试使用以下简单功能删除用户信息: -

    ref.child("UserProfile").child((FIRAuth.auth()?.currentUser?.uid)!).removeValueWithCompletionBlock({ (error, ref) in
       if error != nil {
        print(error)
          } else {
        print("Child Removed Correctly")
       }
})

JSON树:

  {
 "Devices" : {
"Nsguz6iIhUUeFPkcN9ge1KfQnGr1" : {
  "Device1" : {
    "Category" : "أخرى",
    "Description" : "Hello",
    "DeviceName" : "Test",
    "ImageUrl" : "https://firebasestorage.googleapis.com/v0/b/jabeerah-c27c3.appspot.com/o/Devices_Images%2FF3E423AD-D259-4520-93D0-BC8BC9217ECB.png?alt=media&token=8c2f5c08-4293-4b2d-956a-265c9a7b3d02"
  }
 },
"UserProfile" : {
"0HjYidMRvPOxgCR8c8SSrLYUALm2" : {
  "city" : "Jeddah",
  "email" : "test15@gmail.com",
  "name" : "Hello",
  "phone" : "00000"
}

}
}

我一直得到(运行时错误)!

  

致命错误:在解包可选值时意外发现nil

但实际上仪表板中始终存在一个值!

1 个答案:

答案 0 :(得分:1)

  FIRDatabase.database().reference().child("UserProfile").child(FIRAuth.auth()!.currentUser!.uid).removeValueWithCompletionBlock({ (error, refer) in
   if error != nil {
    print(error)
      } else {
     print(refer)
    print("Child Removed Correctly")
   }