gpt4 book ai didi

快速检索数据 Firebase

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

我正在尝试检索已保存在对象中的字符串 key

enter image description here

  func retrieveData() {
let refAll = Database.database().reference().child("Playground")
refAll.observe(.value) { (snapshot) in
if let snapshotValue = snapshot.value as? [String:Any] {
var playgroundSnapshot = snapshotValue
let playgroundKeys = Array(playgroundSnapshot.keys)
self.playgroundArray.removeAll()
for key in playgroundKeys {
guard
let value = playgroundSnapshot[key] as? [String : Any]
else {
continue
}
let title = value["title"] as! String
let city = value["city"] as! String
let location = value["location"] as! String
let price = value["price"] as! String

let playground = Playground(title: title, price: price, location: location, city: city, availblePlayground: true)
self.playgroundArray.append(playground)
}
self.tabeView.reloadData()
}
}
}

在 PlaygroundArray 中,每个对象都有一个键

 keySelected = playgroundArray[indexPath.row].key

但我不知道为什么 keySelected 是 nil 即使 PlaygroundArray 有对象

最佳答案

playgroundArray 不包含“key”。您必须设置Playground Struct。添加var key:String?并将其添加到init()函数中。

let playground = Playground(title: title, price: price, location: location, city: city, availblePlayground: true)

let playground = Playground(title: title, price: price, location: location, city: city, availblePlayground: true, key: key)


self.playgroundArray.append(playground)

关于快速检索数据 Firebase,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52546573/

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