When my app launches I kick off a download in a background thread - download some data and store it in my Core Data store.
At the moment I use the ManagedObjectContext of my main thread. I want to use another ManagedObjectContext for my background thread to avoid the app crashing if I try to play with the same context from 2 threads.
I've been looking at http://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/CoreData/Articles/cdConcurrency.html and I see that I need to create a new ManagedObjectContext for my background thread and not use the main threads one.
But how do I do that?
Do I simply copy the following methods from my AppDelegate
and stick them in to my new class??
There's very little out there what I've found so if anyone knows what the correct way is then, please!
At the moment I use the ManagedObjectContext of my main thread. I want to use another ManagedObjectContext for my background thread to avoid the app crashing if I try to play with the same context from 2 threads.
I've been looking at http://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/CoreData/Articles/cdConcurrency.html and I see that I need to create a new ManagedObjectContext for my background thread and not use the main threads one.
But how do I do that?
Do I simply copy the following methods from my AppDelegate
Code:
- (void)saveContext {
- (NSManagedObjectContext *)managedObjectContext {
- (NSManagedObjectModel *)managedObjectModel {
- (NSPersistentStoreCoordinator *)persistentStoreCoordinator {
There's very little out there what I've found so if anyone knows what the correct way is then, please!