Overridding -[NSPersistentDocument managedObjectContext]
Overridding -[NSPersistentDocument managedObjectContext]
- Subject: Overridding -[NSPersistentDocument managedObjectContext]
- From: Jerry Krinock <email@hidden>
- Date: Mon, 27 Oct 2008 10:49:25 -0700
Documentation for -[NSPersistentDocument managedObjectContext] states:
"If a managed object context for the receiver does not exist, one is
created automatically. You override this method to customize the
creation of the persistence stack."
Well, the first sentence leaves me in a bit of quandary when I try and
follow the second. Something like this won't work:
- (NSManagedObjectContext*)managedObjectContext {
if (![super managedObjectContext]) {
// Create a new MOC...
// Oops, sorry, this branch will never execute.
}
return [self managedObjectContext] ;
}
So it seems like I need to instead use my own instance variable,
myMOC. Something like this should work:
- (NSManagedObjectContext*)managedObjectContext {
if (![self myMOC]) {
NSManagedObjectContext* newMOC ;
//
// ... code to alloc, initialize and configure newMOC
//
[self setMyMOC:newMOC] ;
[myMOC release] ;
}
return [self myMOC] ;
}
But it seems odd that now super's instance variable
managedObjectContext will just sit there forever, pointing to nil. Is
this the proper intended usage?
Thanks,
Jerry Krinock
[1] http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Classes/NSPersistentDocument_Class/Reference/Reference.html#/
/apple_ref/occ/instm/NSPersistentDocument/managedObjectContext
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden