Swift Firebase删除快照子项

Swift Firebase删除快照子项,swift,firebase-realtime-database,Swift,Firebase Realtime Database,我正在使用Firebase作为我的数据库。。。 然后我想删除“codigo”键值。这是我的if声明: let profile = FIRDatabase.database().reference().child("barcodes") profile.observeEventType(.Value, withBlock: { (snapshot) -> Void in for item in snapshot.children {

我正在使用
Firebase
作为我的数据库。。。

然后我想删除
“codigo”
键值。这是我的if声明:

let profile = FIRDatabase.database().reference().child("barcodes")
         profile.observeEventType(.Value, withBlock: { (snapshot) -> Void in


            for item in snapshot.children {

                if item.value["codigo"]as! String == barcodes[indexPath.row].code{
                    print("HERE")

                item.removeValue!()


                }


            }

但它在
item.removeValue()
处崩溃

不能删除快照。但是,您可以获取快照来源的引用并删除该引用:

let profile = FIRDatabase.database().reference().child("barcodes")
profile.observeEventType(.Value, withBlock: { (snapshot) -> Void in
   for item in snapshot.children {
       if item.value["codigo"]as! String == barcodes[indexPath.row].code{
           print("HERE")
           item.ref.removeValue!()
       }
   }
})

您好,我终于找到了解决方案:

let profile = FIRDatabase.database().reference().child("barcodes")
     profile.observeEventType(.Value, withBlock: { (snapshot) -> Void in


          if snapshot.exists(){

                for item in snapshot.children {
                    if item.value["codigo"]as! String == barcodes[index].code{

                        item.ref.child(item.key!).parent?.removeValue()

                    }
                }
            }
        })

非常感谢

你好,德拉维迪安,谢谢你的回复,但它仍然没有在我的firebase控制台上删除,它崩溃了。代码有一些错误,你测试过吗?提前感谢,如果你不能只删除codigo密钥,你可以帮我删除这个“codigo”的自动ID,而且我在if项中有一个错误。1[“codigo”]as!String==条形码[indexPath.row].Code它们都在打印相同的字符串,但在我的条形码数组计数后崩溃…是的,我尝试了@Frank van Puffelen answer,但它删除了所有条形码,我不希望这样。barcodeKey打印“barcodes”Dravidian它终于被删除了我使用了这个代码:FIRDatabase.database().reference().child(“barcodes”).child(item.key!).removeValue()。但他正在删除我所有的数据库,我做什么?谢谢弗兰克,它删除了我所有的数据,我不想这样。我只想删除一个特定的条形码。只是快照中的一个特定项。。。有什么帮助吗?
let profile = FIRDatabase.database().reference().child("barcodes")
     profile.observeEventType(.Value, withBlock: { (snapshot) -> Void in


          if snapshot.exists(){

                for item in snapshot.children {
                    if item.value["codigo"]as! String == barcodes[index].code{

                        item.ref.child(item.key!).parent?.removeValue()

                    }
                }
            }
        })