Я работаю с Firebase. Я могу получить в ответ словарь, который выглядит так:
▿ 0 : 2 elements
- key : "maskForHair"
▿ value : 3 elements
▿ 0 : 2 elements
- key : id
- value : 1
▿ 1 : 2 elements
- key : name
- value : Hair Mask
▿ 2 : 2 elements
- key : note
- value : asd
▿ 1 : 2 elements
- key : "hairShampo"
▿ value : 3 elements
▿ 0 : 2 elements
- key : id
- value : 0
▿ 1 : 2 elements
- key : name
- value : hairShampo
▿ 2 : 2 elements
- key : note
- value : asd
Теперь я пытаюсь заполнить tableView, используя этот словарь, но я не могу найтиспособ добавить этот dict к массиву, есть идеи?
Вот так выглядит моя функция getCategories:
func getCategories(){
dbHandle = dbRefernce?.child("categories").observe(.value, with: { (snapshot) in
if let dictionary = snapshot.value as? [String : Any]{
print(dictionary)
let category = Categories(dictionary: dictionary)
self.categoriesArr.append(category)
DispatchQueue.main.async {
self.categoriesTableView.reloadData()
}
}
})
}
А вот как выглядит мой класс Categories:
import Foundation
import UIKit
class Categories: NSObject {
var name : String? = nil
var id : Int? = nil
var note : String? = nil
init (dictionary: [String: Any]) {
super.init()
name = dictionary["name"] as? String
id = dictionary["id"] as? Int
note = dictionary["note"] as? String
}
}