Every app needs to parse JSON data coming from server and ObjectMapper is a powerful tool to achieve that. It can be easily done with provided pod which can be install by adding following line into podfile:
Now after installing ObjectMapper into your project you need to create objects according to data coming into the JSON response like:
Above code is only essential part of mapping through ObjectMapper. You can see that we have a JSON here as EventResponseModel in which we are getting total event as number, page number as number and all events array which have event model type JSON object. Event model have attributes as event id and event name. By overriding mapping function of Mappable, we can parse JSON data into our object attribute.
Now we are done with object class. We need to create EventResponseObject when we get data from server which will be reused later. Object can be parsed like following code snippet:
var eventResponseModel:EventResponseModel = Mapper<EventResponseModel>().map(responseDictionary)!
Here we can get eventResponseModel by which we retrieve data further. Hope it helps.