Do you have any problems with threads or async tasks during the mapping process? I get a request and map the json via
let json = JSON(responseObject)
var array: Array
for (index: String, subJson: JSON) in json {
let data = Mapper
array.append(data)
}
During the mapping process, the ui on the main thread is blocked. Do you have any ideas what to do about that?
It is entirely possible that mapping is blocking the UI thread. ObjectMapper executes on the thread that it is called from so it is up to the developer make sure that it does not block the UI when executing.
You could do you mapping using Grand Central dispatch like this:
// Do Object mapping on a background queue
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)){
let parsedObject = Mapper<T>().map(JSONResponse)
dispatch_async(dispatch_get_main_queue()){
// use parsedObject on main thread
}
}
Most helpful comment
It is entirely possible that mapping is blocking the UI thread. ObjectMapper executes on the thread that it is called from so it is up to the developer make sure that it does not block the UI when executing.
You could do you mapping using Grand Central dispatch like this: