I'm working on enhancing an existing application to use iCloud so the same data can be accessed on multiple devices.

I'm planning to use document-based storage and to use a file package (i.e. a directory of files represented as single file and handled by NSFileWrapper).

My main question is: are file package updates guaranteed to be atomic? If I open the app and a few files within a single document package have been changed, will iOS download them and then inform my app only when all subfiles are present and in-place? Or is there a risk that the files will come in one by one, leaving me with a potentially inconsistent package?

Also, my existing app uses SQLite (not through Core Data, but rather through a custom wrapper). Some parts of the app will clearly require a nice, indexed SQL database for performance. So my plan is to use the iCloud data as a reference store, keep an SQLite database in the Caches directory for performance reasons (or somewhere else strictly local to the device) and update the database based on what's in iCloud. Changes the user makes in the app will be recorded both in iCloud and in the local database. Is this crazy or reasonable?

1 Answer
1

so my answer to your main question is academic, because i don't have a test-base for testing this, but …

given that your directory is treated as a single-entity, if you coordinate using that entity as the item manipulated by your NSManagedDocument.

i'm basing this answer on my notes from learning about using NSManagedDocument to manage iCloud :

// Conflict
// - what if a device detached from the network changed a document that another device changed?
// and then the detached device re-attached and tried to apply the change and it conflicted?
// one must manage the conflict by looking for the InConflict document state.
// - when it happens, a decision must be made which version of the document to use and/or
// manage changes. probably want to set NSManagedObjectContext's mergePolicy to other than
// default (Error).
// - then update the old, conflicting NSFileVersion to no longer conflict (and remove those
// versions).