I have the following code which parses JSON data from a website. I extracted the data in the form of a dictionary. Now I need to display each element of the dictionary as a cell in the Tableview. Below is my code:
class OrdersSummaryFetchservice{
let shopifyOrdersListURL: URL?
var provinceNamesDictionary = [String: Int]()
init(URL: URL) {
shopifyOrdersListURL = URL
}
func fetchOrdersSummary(completion: @escaping (OrdersSummary) -> Void) {
Alamofire.request(shopifyOrdersListURL!).responseJSON { (response) in
if let orderListInJSON = response.result.value as? [String:Array<Any>]{
if let orderListArray = orderListInJSON["orders"] {
for index in 0...(orderListArray as Array).count-1 {
if let order = orderListArray[index] as? [String:Any] {
if let billingAddress = order["billing_address"] as? [String:Any] {
if let provinceName = billingAddress["province"] as? String {
if (self.provinceNamesDictionary[provinceName] == nil) {
self.provinceNamesDictionary[provinceName] = 1
} else {
let orders = self.provinceNamesDictionary[provinceName]!
self.provinceNamesDictionary[provinceName] = orders + 1
}
}
}
}
}
let ordersSummary = OrdersSummary(provinceNameDictionary: self.provinceNamesDictionary)
completion(ordersSummary)
}
}
}
}
}
So, now I have a dictionary in ordersSummary. How do i display it in the TableView