• 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
Overriding managedObjectContext for a new Persistent Document
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Overriding managedObjectContext for a new Persistent Document


  • Subject: Overriding managedObjectContext for a new Persistent Document
  • From: Carol Clark <email@hidden>
  • Date: Mon, 14 Sep 2009 11:51:58 -0500

I'm trying to override managedObjectContext in my NSPersistentDocument subclass. My document does some work in its init methods (it's modeled on the NSPersistentDocument Core Data Tutorial), so my managedObjectContext method is invoked at init time.

If I understand correctly, creating a NSManagedObjectContext involves creating the object, adding a new NSPersistentStore to the NSPersistentStoreCoordinator for it, and then attaching the NSPersistentStoreCoordinator (why not the NSPersistentStore?) to the NSManagedObjectContext using -[NSManagedObjectContext setPersistentStoreCoordinator].

To add the new Store to the Coordinator, I invoke - [NSPersistentStoreCoordinator addPersistentStoreWithType:configuration:URL:options:error:.
For an existing document, my document's - initWithContentsOfURL:ofType:error: method is invoked with parameters for the file type and URL, so I just pass those in the addPersistentStore... message. For testing, I pass NSInMemoryStoreType with a nil URL. Both of those appear for now to be working fine.


For a new document, my document's initWithType:error: is invoked with a type of "XML", and asking the document for its fileURL at that point returns (null). However, if I pass that value (or nil or [NSNull null]), addPersistentStoreWithType:configuration:URL:options:error: complains (reasonably, it seems) that it "Cannot create an XML store with a nil URL."
(I did try passing "InMemory" instead of (!!) the input value for type just to see what would happen. That appears to work for awhile, but the document created cannot be successfully reopened -- it is unable to fetch its objects.)


So what parameters do I pass to addPersistentStore... for a new document? Or am I coming at this from the wrong direction to begin with?

email@hidden



_______________________________________________

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


  • Prev by Date: XCode Developer issue. Debugger errors since upgrading to Snow Leopard: unable to read unknown load command 0x80000022
  • Next by Date: Re: NSPathControl not displaying icons initially
  • Previous by thread: Re: XCode Developer issue. Debugger errors since upgrading to Snow Leopard: unable to read unknown load command 0x80000022
  • Next by thread: Filtering a table view using NSSearchField
  • Index(es):
    • Date
    • Thread