2

I have a UITableViewlike this:

enter image description here

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)

                ...
           }

       }
   }
Asdrubal
  • 2,421
  • 4
  • 29
  • 37
Mohammadreza
  • 225
  • 5
  • 19

1 Answers1

0

https://gist.github.com/himanshu-benzatine/75fa44dc0e3f2752973a79984b182d70

Check this link and if any problem then tell me. i give you basic idea of how to create tableview with header and selection.

Happy coding

Himanshu Moradiya
  • 4,769
  • 4
  • 25
  • 49