Core Data: NSArrayController's MOC vs NSPersistentDocument's MOC
Core Data: NSArrayController's MOC vs NSPersistentDocument's MOC
- Subject: Core Data: NSArrayController's MOC vs NSPersistentDocument's MOC
- From: "Frederick C. Lee" <email@hidden>
- Date: Mon, 12 Dec 2005 10:42:00 -0800
Environment:
NSPersistentDocument.
It appears I'm working with two versions of ManagedObjectContext (MOC).
Problem:
The GUI doesn't see the data that I had programmatically inserted
into the MOC.
Scenario:
1) Front-End: I have the front-end developed via sliding an entity
(or set of entities) from my project's xdatamodel into my IB's panel:
creating NSArrayControllers that connect the IB objects with the
controller's ManagedObjectContext (MOC).
2) Back-End: I also programmatically add default values to
NSPersistentDocument's MOC as defined in the following:
- (void) setupCoreDataStack {
NSLog(@"{GVDocument.m: setupCoreDataStack}");
// Create the model and coordinator from main bundle:
NSManagedObjectModel *model = [NSManagedObjectModel
mergedModelFromBundles:nil];
persistentStoreCoordinator = [[NSPersistentStoreCoordinator
alloc] initWithManagedObjectModel:model];
// create the context and set its coordinator and merge policy
managedObjectContext = [[NSManagedObjectContext alloc] init];
[managedObjectContext
setPersistentStoreCoordinator:persistentStoreCoordinator];
// [[InferenceCore defaultCore] setValue:managedObjectContext
forKey:@"managedObjectContext"];
// initialize the default store
[self setupDefaultStore];
} // end setupCoreDataStack().
- (void)addNewEntry {
NSError *error;
[self setCountry:[NSEntityDescription
insertNewObjectForEntityForName:@"Country"
inManagedObjectContext:managedObjectContext]];
[[self country] setValue:@"Switzerland" forKey:@"name"];
[[self country] setValue:@"Franc" forKey:@"currency"];
[[self country] setValue:@"
http://info.ch" forKey:@"url"];
// Adding daughter-table data:
NSMutableSet *countryCities = [[self country]
mutableSetValueForKey:@"city"];
City *newCity = (City *)[NSEntityDescription
insertNewObjectForEntityForName:@"City"
inManagedObjectContext:managedObjectContext];
[newCity setValue:@"Basel" forKey:@"name"];
[newCity setValue:[self country] forKey:@"country"];
[countryCities addObject:newCity];
[managedObjectContext processPendingChanges];
BOOL saved = [managedObjectContext save:&error];
// Note: need to sync NSArrayControllers with
managedObjectContext so you can see data in GUI.
return;
}
------------------------------------------------------------------------
---------------
Currently, I see different sets of data when examining the
NSArrayController's arrangedObjects vs MOC's insertedObjects via the
debugger.
My question:
How can I SHARE the SAME MOC between the front-end MOC (that the
NSArrayController sees) with the back-end MOC that
I use to populate programmatically? I want to be able to see the
programmatically-supplied data from the GUI vs only via debugger.
Regards,
Ric.
PS. Thanks mmalc for prompt replies.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden