Hi, all. I am struggling to understand how all Core Data and Managed Object Model actually work. I am a noob as far as objective C and Cocoa go, so it's pretty obvious that I am hitting the learning curve. I've been reading the Core Data docs and the Hilegass book, but there are definitely some holes that I need to fill in. Here goes:
1. What is the difference in my xib Controller in specifying mode = Entity vs. Class? When should I use one or the other?
2. My application will only have a single instance of the model entity, called Network, per document. I am using an ObjectController as opposed to an ArrayController. This seems to be working fine, just want to be convinced that I am on the right path.
3. This question relates to the code snippet below. When I open my application, an new blank document of the Network entity is created. The initWithType: gets invoked, where I set the self.network property. This works fine. When I open an existing Network document, and click a button in my app window, the buildNetwork: gets invoked. I need to set self.network there as well. The [self setNetwork: ...] does not seem to do what I need to do. I've hit my head against the wall on this for a while, and I need to punt.
4. My managed object model has the Network class as the root. There are one to many relationships defined between the Network and two other classes called Node and Path. The Network class has this to contain the Node children
The Node class has this to contain the Path children
This seems to me to be correct, but if I'm wrong please let me know. My application will be creating all of the child Nodes and Paths as needed. Will Core Data correctly save all of the child Nodes and Paths when I save? Or will my ObjectController need to get switched to a TreeController? I'm not sure if it makes a difference, but the Nodes and Paths will never be displayed on a window, edited by the user, etc.
Thanks in advance
1. What is the difference in my xib Controller in specifying mode = Entity vs. Class? When should I use one or the other?
2. My application will only have a single instance of the model entity, called Network, per document. I am using an ObjectController as opposed to an ArrayController. This seems to be working fine, just want to be convinced that I am on the right path.
3. This question relates to the code snippet below. When I open my application, an new blank document of the Network entity is created. The initWithType: gets invoked, where I set the self.network property. This works fine. When I open an existing Network document, and click a button in my app window, the buildNetwork: gets invoked. I need to set self.network there as well. The [self setNetwork: ...] does not seem to do what I need to do. I've hit my head against the wall on this for a while, and I need to punt.
Code:
- (IBAction)buildNetwork:(id)sender {
NetBuilder *netBuilder;
@try
{
[self setNetwork:[[NSDocumentController sharedDocumentController] currentDocument]];
netBuilder = [[[NetBuilder alloc ] init ] retain];
[netBuilder setNetwork:self.network];
[netBuilder buildNetwork];
}
@catch ( NSException *e )
{
NSLog(@"MyDocument error in buildNetwork: %@", [e reason]);
}
[netBuilder release];
}
- (id)initWithType:(NSString *)type error:(NSError **)error {
self = [super initWithType:type error:error];
if (self != nil) {
NSManagedObjectContext *managedObjectContext = [self managedObjectContext];
[[managedObjectContext undoManager] disableUndoRegistration];
self.network = [NSEntityDescription insertNewObjectForEntityForName:@"Network"
inManagedObjectContext:managedObjectContext];
[managedObjectContext processPendingChanges];
[[managedObjectContext undoManager] enableUndoRegistration];
}
return self;
}
4. My managed object model has the Network class as the root. There are one to many relationships defined between the Network and two other classes called Node and Path. The Network class has this to contain the Node children
Code:
@property (retain) NSSet* nodes;
The Node class has this to contain the Path children
Code:
@property (retain) NSSet* outputPaths;
@property (retain) NSSet* inputPaths;
This seems to me to be correct, but if I'm wrong please let me know. My application will be creating all of the child Nodes and Paths as needed. Will Core Data correctly save all of the child Nodes and Paths when I save? Or will my ObjectController need to get switched to a TreeController? I'm not sure if it makes a difference, but the Nodes and Paths will never be displayed on a window, edited by the user, etc.
Thanks in advance