I'm trying to create a new instance of NSManagedObjectContext so that I can perform a fetch request in a thread other than the main one. As I understand it each thread needs it's own instance although they can share stores.
My app is a core data document based app.
Having read a bit here I've got this code:
NSManagedObjectContext *managedObjectContextForThread = nil;
NSPersistentStoreCoordinator *coordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:self.managedObjectModel];
if (coordinator != nil) {
managedObjectContextForThread = [[NSManagedObjectContext alloc] init];
[managedObjectContextForThread setPersistentStoreCoordinator:coordinator];
[managedObjectContextForThread setUndoManager:nil];
}
It runs but when I perform the fetch I get no results, I suspect because the NSPersistentStoreCoordinator isn't getting setup correctly.
How should I be setting that store coordinator to work with my main store? Or is there something else I'm missing here?