Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Thread and async problems... #77

Closed
trainerleipzig opened this issue Mar 7, 2015 · 1 comment
Closed

Thread and async problems... #77

trainerleipzig opened this issue Mar 7, 2015 · 1 comment

Comments

@trainerleipzig
Copy link

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<AF_Poi> = Array()
for (index: String, subJson: JSON) in json {
let data = Mapper<AF_Poi>().map(subJson.dictionaryObject!)
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?

@tristanhimmelman
Copy link
Owner

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
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants