I create and add several managed objects to Core Data from the background queue. I realized that I could not access the context from the background thread, so I used executeBlock to schedule the addition of Core Data back to the same queue in which the context was created. This works great ...
My question during testing, I noticed that by removing [moc performBlock:^{ ... }]; , the application still works as expected (maybe even fractions of a second faster) Do I need to performBlock ? I would suggest that I do this and it just works (for now :) in non-streaming mode, I just wanted to check that my understanding was not a drawback.
dispatch_queue_t backgroundQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0); dispatch_async(backgroundQueue, ^{
EDIT: Added implementation for createRodInContext ...
+ (Rod *)createRodInContext:(NSManagedObjectContext *)context withDictionary:(NSDictionary *)dictionary { // CREATE Rod *rod = [NSEntityDescription insertNewObjectForEntityForName:@"Rod" inManagedObjectContext:context]; // POPULATE [neo setDataCode:[dictionary objectForKey:@"dataCode"]]; [neo setDataName:[dictionary objectForKey:@"dataName"]]; [neo setDataReference:[dictionary objectForKey:@"dataReference"]]; ... return rod; }
source share