作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用以下方法获取 firebase 数据库中的所有产品,但我需要获取自动生成的 key 。我应该怎么做才能做到这一点?
func fetchProducts(){
self.ref.child("products").observe(.childAdded, with: { (snapshot) in
//print(snapshot)
let proObject = snapshot.value as! NSDictionary
let description = proObject["description"] as! String
let categories = proObject["category"] as! Array<String>
let images = proObject["image"] as! Array<String>
let name = proObject["name"] as! String
let price = proObject["price"] as! Int
let qty = proObject["qty"] as! Int
let pro = Product(name: name, qty: qty,
images: images, price: price, category: categories, description: description)
self.items.append(pro)
})
}
最佳答案
自动生成的 key 在 snapshot.key
属性中可用。
Firebase documentation对于此属性:
The key of the location that generated this FIRDataSnapshot.
关于ios - 如何在 Firebase 中检索自动生成的 ID/ key ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43705623/
我是一名优秀的程序员,十分优秀!