I am developing an application with Swift 4. Where I make a call to the APIRest with Alamofire and I want to map the JSON response with Objectmapper. Well, the JSON that calls me back is the following:
The code to the APIRest is:
func retrievePostListData() {
Alamofire
.request("http://www.speedrun.com/api/v1/games", method: .get)
.validate()
.responseArray(completionHandler: { (response:
DataResponse<[PostModelSpeedRunModel]>) in
switch response.result {
case .success(let posts):
self.remoteRequestHandler?.onPostsRetrievedData(posts)
case .failure( _):
self.remoteRequestHandler?.onError()
}
})
}
The problem is that I do not know how to access each of the values (func mapping). Because there are some nested values. In addition to that some of the annunciations are objects and others are array. My erroneous code is the following:
import Foundation
import ObjectMapper
struct PostModelSpeedRunModel {
var id = ""
var international = ""
var abbreviation = ""
var links = [Links]??? // I need to get "rel" and "uri" of "runs"
var uri = ""
}
extension PostModelSpeedRunModel: Mappable {
init?(map: Map) {
}
mutating func mapping(map: Map) {
id <- map["data.id"]
international <- map["data.international"]
abbreviation <- map["data.abbreviation"]
link <- map["data.Links"]
uri <- map["data.logo"]
}
}
Can you help me do / understand doing the function mapping? Thanks