I can't get all elements of my array. I think the problem is in my Model, but i don't know how to correct it. The following JSON is given:
{
"statusCode": 200,
"message": "Success",
"content": [
{
"description": {
"1": {
"name": "First",
"cost": 200,
"count": 1
},
"2": {
"name": "Second",
"cost": 500,
"count": 1
}
},
"sum": 700,
"created_at": "13.11.2018 17:22"
}
]
}
My Model:
// MARK: - History
struct History: Codable {
let statusCode: Int
let message: String
let content: [History_Content]
}
// MARK: - Content
struct History_Content: Codable {
let description: [String: History_Description]
let sum: Int
let created_at: String
enum CodingKeys: String, CodingKey {
case description
case sum
case created_at
}
}
// MARK: - Description
struct History_Description: Codable {
let name: String
let cost, count: Int
}
My cellForRowAt :
var arrData = [History_Content]().
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "history_cell", for: indexPath) as! HistoryTableViewCell
cell.time.text = arrData[indexPath.row].created_at
for i in arrData[indexPath.row].description.self{
cell.desc.text = "You bought \"\(i.value.name)\""
}
return cell
}
I just get a single element of description. How can i get all elements of this array? What do i need to change in my code?
arrData?let description: [String: History_Description](dictionary) tolet description: [History_Description](array)