Question

My code looks like something like this:

dispatch_async(background_save_queue, ^{

        NSManagedObjectContext *context = [[NSManagedObjectContext alloc] init];
        [context setMergePolicy:NSMergeByPropertyObjectTrumpMergePolicy];
        [context setPersistentStoreCoordinator:coordinator];
        [[NSNotificationCenter defaultCenter] addObserver:mainContext selector:@selector(mergeChangesFromContextDidSaveNotification:) name:NSManagedObjectContextDidSaveNotification object:context];


        //code to create objects with core data in context ("context" variable)

        [context save:nil];
        [context release];
}

And the similar code without multithread (with one context only) works much better.

Is my code wrong and are there are other examples of filling core data objects with multithreading?

Était-ce utile?

La solution

Finally I checked that another thread is not slower than the main one. The problem is there are a lot of records in a data source and I need to perform a check for each record if this record already written in database. So the speed of my database creation process depends greatly on a count of the records and a database structure.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top