Overriding managedObjectContext for a new Persistent Document
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