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){
//UserTasks
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"]];
if(oldUserTask)
{
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!
I ended up not using MagicalRecord to get the behavior I was looking for– I followed this post:
https://stackoverflow.com/a/11814957/480415
Now my UI is not locked up while updating entities in the background.