How do I create a data model with SwiftyJSON and a 2nd set of nested array of objects? I'm able to parse and store the top level objects fine, but not the inner ones. noteimages in particular, I can't seem to figure out. Below is the api results and under that is how I am trying to do it, although not quite right.
[
{
"id": 1,
"title": "some title",
"details": "here are some details",
"userId": 1,
"hidden": false,
"createdAt": "2018-02-14T07:02:33.000Z",
"updatedAt": "2018-02-14T07:02:33.000Z",
"contactId": 1,
"noteimages": [
{
"id": 2,
"imageUrl": "someimage222.jpg",
"userId": 1,
"hidden": false,
"createdAt": "2018-02-14T07:02:58.000Z",
"updatedAt": "2018-02-15T04:41:05.000Z",
"noteId": 1
}
]
}
]
Alamofire.request(url, method: .get, parameters: nil, encoding: JSONEncoding.default, headers: header).responseJSON { (response) in
if response.result.error == nil {
guard let data = response.data else { return }
do {
if let json = try JSON(data: data).array {
print(json)
for item in json {
let title = item["title"].stringValue
let details = item["details"].stringValue
var noteImages: [Dictionary<String, AnyObject>]
for image in item["noteimages"].arrayValue {
noteImages.append(image["imageUrl"])
}
let note = Note(title: title, details: details, noteImage: noteImages)
self.notes.append(note)
}
//print(response)
completion(true)
}
} catch {
debugPrint(error)
}
} else {
completion(false)
debugPrint(response.result.error as Any)
}
}