Skip to content

Access Core Data Entities while updating them in background #367

ryang1428 opened this Issue Jan 7, 2013 · 0 comments

1 participant


In my iOS app I am hitting a web service when the app loads to check for updates to various tables(entities) in my Core Data DB.

I do this in a background thread so the user can still interact with the app

The issue I am having is when I try to load a view that contains a table of entities that I access from Core Data-- the app becomes unresponsive and lags until the background updating is complete.

Is it possible to have a lag-less experience if for example I touch to view my table of "Tasks" while in the background I am updating those "Tasks"?

I am using MagicalRecord and performing my creates/updates in a saveInBackgroundWithBlock block

 [MagicalRecord saveInBackgroundWithBlock:^(NSManagedObjectContext *localContext){      
    if([viewName isEqualToString:[[NSString stringWithFormat:@"UserTask_vw_iSales"] lowercaseString]])
        //returns a UserTask or nil if one does not exist
        UserTask *oldUserTask = [UserTask doesExist:[record valueForKey:@"JSONData"]];

            NSLog(@"deleting old UserTask");

            [UserTask MR_deleteAllMatchingPredicate:[NSPredicate predicateWithFormat:@"userTaskUID == %@", oldUserTask.userTaskUID] inContext:localContext];

        //create new one 
        UserTask *utt = [UserTask MR_createInContext:localContext];
        [utt initWithJSONSting:[record valueForKey:@"JSONData"]];

        NSLog(@"Creating UserTaskType: %@", utt.userTaskUID);

Thanks for any help!

@ryang1428 ryang1428 closed this Jan 9, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.