small medium large xlarge

Back to: All Forums  Core Data
Generic-user-small
28 May 2010, 15:10
Snow Crash (1 post)

Working through Multithreading (Chapter 9) I’m a little confused by how the MOCs are set up in PPImportOperation.m. One is the importContext MOC and the other is the mainMOC. The question I have is:

They both have an NSPersistentStoreCoordinator set up when the MOCs are set up but they are both done differently - i.e one uses “[self persistentStoreCoordinator]” and the other uses “[appDelegate persistentStoreCoordinator]”. Why is that?

- (NSManagedObjectContext*)managedObjectContext
{
  NSPersistentStoreCoordinator *coord = [self persistentStoreCoordinator];
  if (!coord) return nil;
  NSManagedObjectContext *moc = [[NSManagedObjectContext alloc] init];
  [moc setPersistentStoreCoordinator: coord];
  return [moc autorelease];
}
//START:newContextToMainStore
- (NSManagedObjectContext*)newContextToMainStore
{
  NSPersistentStoreCoordinator *coord = nil;
  coord = [appDelegate persistentStoreCoordinator];
  
  NSManagedObjectContext *moc = [[NSManagedObjectContext alloc] init];
  [moc setPersistentStoreCoordinator:coord];
  return [moc autorelease];
}
//END:newContextToMainStore
You must be logged in to comment