문제

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?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top