Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

dantastic

macrumors 6502a
Original poster
Jan 21, 2011
572
678
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
Code:
- (void)saveContext {
- (NSManagedObjectContext *)managedObjectContext {
- (NSManagedObjectModel *)managedObjectModel {
- (NSPersistentStoreCoordinator *)persistentStoreCoordinator {
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! :D
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.