views:

233

answers:

0

Following the advice in the Core Data Programming Guide's Core Data Performance page 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. 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 a NSPersistentDocument save 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)?