У меня есть этот пустой словарь
let orderArray = ["name":"","quntity":"","price":""]
и когда я загружаю данные из Firebase, я хочу получить некоторые элементы и поместить их в словарь, чтобы прочитать их позже
Вот мой метод Firebase:
self.databaseRef.child("Users").child((Auth.auth().currentUser?.uid)!).child("cart").child(self.orderFromKitchen).observe(DataEventType.value, with: { (snapshot) in
//if the reference have some values
if snapshot.childrenCount > 0 {
//clearing the list
self.ordersList.removeAll()
//iterating through all the values
for info in snapshot.children.allObjects as! [DataSnapshot] {
//getting values
//let key = self.kitchensRef.childByAutoId().key
let infoObject = info.value as? [String: AnyObject]
let name = infoObject?["name"]
let Id = infoObject?["ID"]
let img = infoObject?["img"]
let price = infoObject?["price"]
let quantity = infoObject?["quntity"]
self.nameArr.append((name as! String?)!)
self.quaArr.append((quantity as! String?)!)
let info = ordersModel(id: Id as! String?, name: name as! String?, img: img as! String?, price: price as? Int,quantity:quantity as! String?)
//here i want to add name and price to the dictionary
self.orderArray.insert(contentsOf: "\(infoObject?["name"]!)", at: 0)
self.orderArray.insert(contentsOf: "\(infoObject?["price"]!)", at: 2)
self.ordersList.append(info)
}
//reloading the tableview
self.tableView.reloadData()
self.loadingView.isHidden = true
}