• 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: Getting managedObject Context
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Getting managedObject Context


  • Subject: Re: Getting managedObject Context
  • From: Quincey Morris <email@hidden>
  • Date: Sat, 29 Aug 2009 16:34:31 -0700

On Aug 29, 2009, at 15:59, Clayton Leitch wrote:

I have spent the last month try to solve a simple problem. I need to get the managedObjectContext in a NSDocument based application. I know how to get this in a non-document based application
-(NSManagedObjectContect *)managedObjectContext {
if (!managedObjectContext) {
managedObjectContext = [[NSApp delegate] managedObjectContext];
}
return managedObjectContext;
}


From the documentation it appears that I get the managedObject Context from the MyDocument instead of the application delegate. I tried a similar structure to the above replacing NSApp delegate with MyDocument. Does anyone have an example of getting the manageObjectContext from the MyDocument class?

You haven't given quite enough information here.

If you mean that your documents are themselves Core Data stores, then you need your document subclass (MyDocument) to be a subclass of NSPersistentDocument instead of NSDocument. If you started from the Core Data document-based application template in Xcode, that's what you were given to start with. Then getting the MOC is easy -- NSPersistentDocument has a 'managedObjectContext' property which you simply access.

Since you mention "replacing NSApp delegate with MyDocument", it's possible you're trying to get the MOC from your MyDocument *class* object ("[MyDocument managedObjectContext]"). If so, that of course doesn't work. It's an instance property ("[myDocument managedObjectContext]").

If you mean that your documents are not Core Data stores, but refer to a shared Core Data store, then of course you continue to ask the application delegate for the MOC.


_______________________________________________

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: 
 >Getting managedObject Context (From: Clayton Leitch <email@hidden>)

  • Prev by Date: Getting managedObject Context
  • Next by Date: Re: Getting managedObject Context
  • Previous by thread: Getting managedObject Context
  • Next by thread: Re: Getting managedObject Context
  • Index(es):
    • Date
    • Thread