Re: Core Data: save to multiple files?
Re: Core Data: save to multiple files?
- Subject: Re: Core Data: save to multiple files?
- From: Chris Hanson <email@hidden>
- Date: Sun, 1 Apr 2007 13:01:55 -0700
On Mar 31, 2007, at 8:20 AM, Patrick Crosby wrote:
I have a document-based core data app with something like:
Document -> has many -> Page -> has many -> Block
(one Document object which has many Page objects. Each Page object
has many Block objects.)
It all works fine and saves the document to one big file.
Say for some perverse reason I want to save each Page object (and the
many Block objects that belong to it) to separate files, one file per
Page. Is this possible?
Yes. You need to do three things:
(1) Break your Document <--->> Page relationship pair, and represent
it some other way because Core Data does not support cross-store
relationships. It might be useful to represent it as a transient
relationship pair instead, and use a some other identifier in an
attribute on Document and Page to implement your own key.
(2) Add multiple persistent stores to your
NSPersistentStoreCoordinator, one to represent each page. You can do
this at any point prior to save.
(3) Use -[NSManagedObjectContext assignObject:toPersistentStore:] to
associate specific managed objects with specific persistent stores.
You can also do this at any point prior to save.
I believe this is covered in the CoreRecipes sample code on the Apple
Developer Connection web site.
-- Chris
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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