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?

carolcl...@cox.net



_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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 arch...@mail-archive.com

Reply via email to