Database Reference
In-Depth Information
This can be fixed.
Baseline/PPRecipes/PPRImportOperationAlt1.m
NSManagedObjectContext *localMOC = nil;
NSUInteger type = NSConfinementConcurrencyType;
localMOC = [[NSManagedObjectContext alloc] initWithConcurrencyType:type];
[localMOC setParentContext:[self mainContext]];
The first change is to initialize our local NSManagedObjectContext as a type of
NSConfinementConcurrencyType . This step locks the NSManagedObjectContext to our
thread. Next, we configure the NSManagedObjectContext to be a child of the main
NSManagedObjectContext .
The other changes are to remove code.
First, we no longer need to listen for change notifications. As soon as we save
the local NSManagedObjectContext , the changes are moved up to our parent
NSManagedObjectContext .
Since we are no longer listening for change notifications, we no longer need
our -contextDidSave: method. Changes now propagate automatically.
These alterations are the only changes required. Once they're in place, we
will no longer block the main thread on saves. We could even increase our
save frequency so the user can see the recipes coming in one at a time, if we
wanted. Without a disk I/O cost or a main thread block, we have a lot more
options for how to handle the user experience.
These are just two examples of how the iOS 6.0/Mac OS X 10.8 changes to
Core Data can improve the performance of our applications. As developers
become more familiar with these new tools, we can expect to see many more
innovative ways that Core Data will be used.
5.6
Wrapping Up
In this chapter, we explored the often-controversial subject of multithreading.
There are a number of myths about Core Data and threading, but with this
foundation, deciding whether to add multithreading to your Core Data
application should be a great deal clearer.
 
 
 
Search WWH ::




Custom Search