gpt4 book ai didi

ios - 删除 firebase 中的对象

转载 作者:行者123 更新时间:2023-11-30 12:51:07 26 4
gpt4 key购买 nike

我有一个条形表,想要使用该条形的存储图像从其中删除单个条形。我使用该栏的名称来删除该栏。

The bar name is unique - I query the name of the bar before adding a new bar to make sure no two bars have the same name.

这是我的职能以及我如何做到这一点。我在从数据库中删除 bar 对象时遇到问题。当然,当我这样做时,它删除了整个条形表。有没有办法获取该栏的 key 或 autoId 的 id 以便能够将其删除。正确的做法是什么。

    func deleteBar(name:String ,completion:@escaping (_ status:Bool, _ msg:String?)->() )
{
let ref = FIRDatabase.database().reference(fromURL: dbURL).child("bars").child(name)
storage = FIRStorage.storage()

// print(key)

let locationRef = FIRDatabase.database().reference(fromURL: dbURL).child("bar_locations")
//delete from bars
ref.parent?.removeValue() //This deleted the whole bars table
//delete from location
locationRef.child(name).removeValue()

let storageRef = storage?.reference(forURL: storageURL).child("bars").child(name).child("logo.jpg")
storageRef?.delete(completion: { (err) in

if err == nil {

completion(true, "Deleted")

} else {
//print(err?.localizedDescription ?? <#default value#>)
completion(false, err?.localizedDescription)
}
})

}

最佳答案

您可能想看看这个很棒的教程。该视频详细介绍了如何在 Swift 中使用 Firebase 执行此操作。您也应该查看整个播放列表:

https://www.youtube.com/watch?v=KkHEEhftUk0&list=PL0dzCUj1L5JEfHqwjBV0XFb9qx9cGXwkq&index=22

关于ios - 删除 firebase 中的对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40960254/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com