I have a UITableView
like this:
and a tableView
data fetch from JSON with Alamofire
and SwiftyJson
:
JSON Data:
{
"timeline": {
"Milan": {
"place": [
{
"name": "Place 1",
"kind": "historic",
},
{
"name": "Place 2",
"kind": "historic",
},
{
"name": "Place 3",
"kind": "historic",
},
{
"name": "Place 4",
"kind": "historic",
}
]
},
"Paris": {
"place": [
{
"name": "Place 1",
"kind": "historic",
},
{
"name": "Place 2",
"kind": "historic",
},
{
"name": "Place 3",
"kind": "historic",
}
]
}
}
}
my question is how I separate city place in one array that inherit from class called Place and put data in tableView like above image.
struct Place {
var name = ""
var type = ""
}
I wrote some code in Alamofire
.success
but this is not enough:
if let jsonData = response.result.value {
let json = JSON(jsonData)
if let items = json["timeline"].dictionary {
for (key,subJson):(String, JSON) in items {
self.cityName.append(key)
...
}
}
}