• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Overridding -[NSPersistentDocument managedObjectContext]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Overridding -[NSPersistentDocument managedObjectContext]


  • Subject: Re: Overridding -[NSPersistentDocument managedObjectContext]
  • From: Andy Lee <email@hidden>
  • Date: Mon, 27 Oct 2008 15:32:47 -0400

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@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


References: 
 >Overridding -[NSPersistentDocument managedObjectContext] (From: Jerry Krinock <email@hidden>)
 >Re: Overridding -[NSPersistentDocument managedObjectContext] (From: Andy Lee <email@hidden>)
 >Re: Overridding -[NSPersistentDocument managedObjectContext] (From: Jerry Krinock <email@hidden>)

  • Prev by Date: Re: how to self-delete app
  • Next by Date: Re: Overridding -[NSPersistentDocument managedObjectContext]
  • Previous by thread: Re: Overridding -[NSPersistentDocument managedObjectContext]
  • Next by thread: Re: Overridding -[NSPersistentDocument managedObjectContext]
  • Index(es):
    • Date
    • Thread