• 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: Ron Lue-Sang <email@hidden>
  • Date: Mon, 27 Oct 2008 13:25:43 -0700


On Oct 27, 2008, at 12:40 PM, Andy Lee wrote:

On Oct 27, 2008, at 3:25 PM, Ron Lue-Sang wrote:
On Oct 27, 2008, at 10:49 AM, Jerry Krinock wrote:
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?


Yes, that's the intended usage. Use your own storage or call super.

Should he also override -setManagedObjectContext:?

He may choose to. It may be sufficient for him to create a new context in init and call [self setManagedObjectContext:] and never have to override either accessor.


If you're worried about some other context being set here, then yea. You'd need to override this and check/handle when the context isn't one of "yours".



My 2 cents: this seems like a brittle design -- it expects the overrider to know that the superclass never uses the ivar directly except in accessors, and it expects the implementer of the base class to remember never to use the ivar directly. In any case, I think the documentation could be clearer and I'll send feedback to that effect.

Yea, I see your point. Please file away. Thanks



--Andy



--------------------------
RONZILLA



_______________________________________________

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: Ron Lue-Sang <email@hidden>)
 >Re: Overridding -[NSPersistentDocument managedObjectContext] (From: Andy Lee <email@hidden>)

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