How to manage a separate data file while saving an NSPersistentDocument or during schema migration
How to manage a separate data file while saving an NSPersistentDocument or during schema migration
- Subject: How to manage a separate data file while saving an NSPersistentDocument or during schema migration
- From: "Barry Wark" <email@hidden>
- Date: Fri, 16 Jan 2009 10:00:44 -0800
Following the advice in
http://developer.apple.com/documentation/Cocoa/Conceptual/CoreData/Articles/cdPerformance.html#//apple_ref/doc/uid/TP40003468-SW5
regarding storage of BLOBs, I've chosen to store binary data for my
NSPersistenDocument-based app (Leopard-only, if that makes a
difference) in an external file (separate from the document Core Data
data store) and keeping an archived NDAlias reference to that file in
my document's data store. Ultimately, I would like the external data
file to end up in the same directory as the document (data store)
file. Since I may need to write data to the external data file before
the document is saved (this is a scientific data acquisition app and
losing data due to a crash is to be avoided if possible), I've taken
the following approach:
I would like to encapsulate the management of this external file in
the model-related classes since I will need the same functionality
during schema migration. Thus managing the external data file in my
NSPersistentDocument's subclass seems wrong. Thus, in the object
model's root object, I create the external file in
NSTemporaryDirectory() in the root objects awakeFromInsert method and
store the NDAlias referencing the data file. I would then like to move
the external data file to the same directory as the saved data store,
when a save occurs. I thought didSave would be the appropriate place
to do it, but it looks like during invocation of the didSave method,
the persistent store is still in a temporary directory (presumably
before being FSExchangeObjects'd to create an atomic save operation).
I plan to factor the logic in awakeFromInsert and didSave into class
methods so that they can be called during schema migration in a custom
entity policy's
createDestinationInstancesForSourceInstance:entityMapping:manager:error:
and endInstanceCreationForEntityMapping:manager:error: respectively.
So, my question: when during NSPersistentDocument save and during
schema migration can I be assured that my root object's
objectID.persistentStore.URL is the 'final' URL of the save (e.g.
where the user chose to save the file for document save)?
thanks,
Barry
_______________________________________________
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