Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8741923
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:24:21+00:00 2026-06-13T11:24:21+00:00

Hello I am Riccardo and I am an indie developer! it’s not a lot

  • 0

Hello I am Riccardo and I am an indie developer!

it’s not a lot that I have been starting programming in objective-c, and I am still a novice! 😀

I started to learn Core Data and everything was going fine until I faced concurrency!
With Core Data my app was continuing to block during save actions, so I googled for core data with background context and I found Magical Record.

With Magical Record I have drastically reduced the complexity of my code 🙂
But I have still one problem, I read everything about Magical Record, I tried to fix it using different methods but the UI freeze is still there 🙁 so I don’t know how to fix it…

Although I think there are problem in all method (looking at freeze UI) 3 of the 4 methods listed are really fast so it is not perceptible.
The only method that as huge problem and you can actually notice a freeze is this one –>

  • (void) persistAppsFromArray: (NSArray *) arrayOfApps inResearch: (NSDictionary *) info;

Where I take an array in order to create all the apps objects and after I associate (after a fetch to find the research, I use the dictionary to create predicates) these apps to the research.

This is my code. It is actually a whole class that manage core data stuff.
I don’t use queues or threads in the class that call these methods, so I think there is something to fix here :-/

I thank you in advance 🙂

#import "CoreDataHelper.h"
#import "CoreData+MagicalRecord.h"


@implementation CoreDataHelper

#pragma mark - Research creator helper

+ (ResearchType *) fetchResearchWithDictionary: (NSDictionary *) info {

// Fetch
// predicates for fetch
NSPredicate * predicateCategory = [NSPredicate predicateWithFormat:@"researchCategory = %@" , [info objectForKey: @"Category"]];
NSPredicate * predicateType = [NSPredicate predicateWithFormat:@"researchType = %@" , [info objectForKey: @"Type"]];
 NSPredicate * predicatePrefix = [NSPredicate predicateWithFormat:@"researchPrefix = %@" , [info objectForKey: @"Prefix"]];

 NSArray * predicates = [NSArray arrayWithObjects: predicateCategory, predicateType, predicatePrefix, nil];

        // create the composite predicate
        NSPredicate * predicateComposito = [NSCompoundPredicate andPredicateWithSubpredicates:predicates];

    // obtain the result
    // Passo la ricerca al brain
   return [ResearchType MR_findFirstWithPredicate: predicateComposito];
}

   + (void)updateResearchWithDictionary:(NSDictionary *) info withCompletionBlock:(completion_block)updatedResearch {

    // Get the context
    NSManagedObjectContext *localContext    = [NSManagedObjectContext MR_context];

    // predicates
    NSPredicate * predicateCategory = [NSPredicate predicateWithFormat:@"researchCategory = %@" , [info objectForKey: @"Category"]];
    NSPredicate * predicateType = [NSPredicate predicateWithFormat:@"researchType = %@" , [info objectForKey: @"Type"]];
    NSPredicate * predicatePrefix = [NSPredicate predicateWithFormat:@"researchPrefix = %@" , [info objectForKey: @"Prefix"]];

    NSArray * predicates = [NSArray arrayWithObjects: predicateCategory, predicateType, predicatePrefix, nil];

    // composite predicate
    NSPredicate * predicateComposito = [NSCompoundPredicate andPredicateWithSubpredicates:predicates];

// create research object 
    ResearchType *research = [ResearchType MR_findFirstWithPredicate: predicateComposito inContext:localContext];



// new properties
    research.researchDate      = [info objectForKey:@"Research Date"];
    research.researchLimit     = [info objectForKey:@"Limit"];
    //research.apps              =  nil;

  [localContext MR_saveInBackgroundCompletion:^{

      updatedResearch(research);

  }];
 }

   + (void) persistResearchWithDictionary: (NSDictionary *) info withCompletionBlock:(completion_block)savedResearch {

// Get the context
NSManagedObjectContext *localContext    = [NSManagedObjectContext MR_context];

// Create a new Person in the current thread context
ResearchType * research   = [ResearchType MR_createInContext:localContext];

// Set properties
research.researchCategory    = [info objectForKey:   @"Category"];
research.researchPrefix      = [info objectForKey:   @"Prefix"];
research.researchCategoryUrl = [info objectForKey:   @"Category Code Url"];
research.researchType        = [info objectForKey:   @"Type"];


research.researchCountry     = [info objectForKey:   @"Country"];
research.researchCountryCode = [info objectForKey:   @"Country Code"];
research.researchDate        = [info objectForKey:   @"Research Date"];
research.researchDevice      = [info objectForKey:   @"Device"];
research.researchLimit       = [info objectForKey:   @"Limit"];

// Save changes
 [localContext MR_saveInBackgroundCompletion:^{

   savedResearch(research);
 }];

 }

    + (void) persistAppsFromArray: (NSArray *) arrayOfApps inResearch: (NSDictionary *) info  {


// Get the local context
    NSManagedObjectContext *localContext    = [NSManagedObjectContext MR_context];

 [localContext MR_saveInBackgroundCompletion:^{


     // predicates
     NSPredicate * predicateCategory = [NSPredicate predicateWithFormat:@"researchCategory = %@" , [info objectForKey: @"Category"]];
     NSPredicate * predicateType = [NSPredicate predicateWithFormat:@"researchType = %@" , [info objectForKey: @"Type"]];
     NSPredicate * predicatePrefix = [NSPredicate predicateWithFormat:@"researchPrefix = %@" , [info objectForKey: @"Prefix"]];

     NSArray * predicates = [NSArray arrayWithObjects: predicateCategory, predicateType, predicatePrefix, nil];

     // Composite predicate
     NSPredicate * predicateComposito = [NSCompoundPredicate andPredicateWithSubpredicates:predicates];

     ResearchType * researchBgContext = [ResearchType MR_findFirstWithPredicate: predicateComposito];

     for (NSDictionary * info in arrayOfApps) {

         AppInDb * app             = [AppInDb MR_createEntity];

         app.appName                  = [info objectForKey: @"App Name"];
         app.appItunesLink            = [info objectForKey: @"iTunes Link"];
         app.appBundleID              = [info objectForKey: @"Bundle ID"];
         app.appID                    = [info objectForKey: @"ID"];
         app.appPriceLabel            = [info objectForKey: @"Price Label"];
         app.appReleaseDate           = [info objectForKey: @"Release Date String"];
         app.appIconImageLink         = [info objectForKey: @"Image Link 100"];
         app.appDeveloperPageLink     = [info objectForKey: @"Developer Page Link"];
         app.appDeveloper             = [info objectForKey: @"Developer"];
         app.appRights                = [info objectForKey: @"Rights"];
         app.appDescription           = [info objectForKey: @"App Description"];
         app.appCategory              = [info objectForKey: @"App Category"];
         app.appCategoryNumber        = [info objectForKey: @"Category Number For Url"];


         // adding app to the related research (one to many relationship)
         [researchBgContext addAppsObject:app];



           }
       }];

     }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T11:24:22+00:00Added an answer on June 13, 2026 at 11:24 am

    Try with this method:

    [MagicalRecord saveInBackgroundWithBlock:^(NSManagedObjectContext *localContext)block {
    }];

    There are a number of other methods you can use, but this should give you a good start. MagicalRecord will create the context for you and everything happens on the background thread. It will also save to the parent context automatically.

    I recommend reading this great article: Core Data and Threads, Without the Headache by Saul Mora who’s the person behind MagicalRecord. It’s a great read which informs you about the many advantages of MagicalRecord.

    Good luck!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello! I've been programming for a long time but just started developing for android,
Hello all and thanks for the attention! I have a problem that must both
Hello everyone I have converted a project in C# to F# that paints the
hello i have a desktop application that communicate with a wcf service that i
Hello, I have a short question. I would like to reset a variable that
Hello guys that is not normal :) !! foo.php <?php if (isset($_POST['data'])) $stringData =
Hello good morning everyone, i have an iphone app which is still in development
Hello the problem I'm having is this, I have a landing page (event.php) that
Hello I am creating a application that uses arraylists ( practice purposes not real
Hello I have read an example that I found on my school database about

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.