Firebase快速删除快照的孩子 [英] Firebase remove snapshot children swift

查看:109
本文介绍了Firebase快速删除快照的孩子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



然后我想删除codigo键值。这是我的if语句:
$ b $ pre $ let profile = FIRDatabase.database()。reference()。child(barcodes)
profile.observeEventType(.Value,withBlock:{(snapshot) - >在


中无效作为snapshot.children中的物品{

如果物品.value [codigo] as!String ==条形码[indexPath.row] .code {
print(HERE)

item.removeValue!()





$ / code>

但它崩溃在 item.removeValue()

解决方案

我终于找到了一个解决方案:
$ b $ $ p $ let profile = FIRDatabase.database()。reference()。child(barcodes)
profile.observeEventType(.Value,withBlock:{(snapshot) - > Void in


if snapshot.exists(){

for item在snapshot.children {
如果我tem.value [ codigo]作为! String == barcodes [index] .code {

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

}
}


$ / code $ / pre
$ b $ p

非常感谢! $ b

I am using Firebase as my Database...

Then i want to delete the "codigo" key value. This is my if statement:

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!()


                }


            }

but it crashes at item.removeValue().

解决方案

Hello there i finally find a solution:

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()

                    }
                }
            }
        })

Thanks a lot!

这篇关于Firebase快速删除快照的孩子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆