我使用以下方法获取firebase数据库中的所有产品,但我需要获取自动生成的密钥。我该怎么做才能实现这一目标?
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)
})
}