On Oct 27, 2008, at 3:12 PM, Jerry Krinock wrote:
On 2008 Oct, 27, at 11:44, Andy Lee wrote:- (NSManagedObjectContext*)managedObjectContext { NSManagedObjectContext* moc = /* ... create your own MOC ... */; [self setManagedObjectContext:moc]; return moc; }Or alternatively, if your intent is to use the inherited behavior but do some additional stuff to the MOC:- (NSManagedObjectContext*)managedObjectContext { NSManagedObjectContext* moc = [super managedObjectContext]; // ... Do custom stuff to moc ... return moc; }Thanks, Andy. It looks like I would then be creating a new moc, or doing custom stuff to it, whenever this getter is invoked. No good.
Ah, I see my first proposed solution doesn't actually work, because it *always* creates a new moc without checking whether it's done so already. But you can't use [super managedObjectContext] to check this, because it will use the inherited behavior to create its own moc.
I'm still not sure whether or not it is appropriate to not use super's managedObjectContext instance variable, as proposed at the bottom of my original post.
I don't see that instance variable. I only see a private _managedObjectContext instance variable in the header, which you wouldn't have access to anyway. Am I missing something?
It might be worth sending feedback on the documentation for - [NSPersistentDocument managedObjectContext]. I agree it's unclear *how* you're supposed to override it. If they wanted to provide a way to override the creation, I think they should have factored it out into a separate method, perhaps -createManagedObjectContext, that would get called by -managedObjectContext. But they didn't.
--Andy _______________________________________________ Cocoa-dev mailing list ([email protected]) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
