Migrating an existing iOS app for SQLite to iCloud: how atomic is iCloud?

I am working on improving an existing application for using iCloud so that they can access the same data on multiple devices.

I plan to use document-based storage and use a package of files (i.e. a directory of files presented as a single file and processed by NSFileWrapper ).

My main question is: are package file updates guaranteed to be atomic? If I open the application and several files in one package of documents are changed, iOS will say them and then report about my application only when all the subfiles are present and in place? Or is there a risk that the files will appear one after another, leaving me a potentially inconsistent package?

In addition, my existing application uses SQLite (not through Core Data, but through a custom shell). Some parts of the application clearly require a good indexed SQL database for performance. So my plan is to use iCloud data as a link store, store the SQLite database in the Caches directory for performance reasons (or somewhere else strictly local to the device) and update the database based on what is in iCloud. Changes made by the user to the application will be recorded both in iCloud and in the local database. Is it crazy or sensible?

+4
source share
1 answer

so my answer to your main question is academic because I don’t have a test base to test this, but ...

given that your directory is considered as a single object if you coordinate the use of this object as an element managed by your NSManagedDocument.

I base this answer on my notes from exploring 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 mergePolicy to other than // default (Error). // - then update the old, conflicting NSFileVersion to no longer conflict (and remove those // versions). 

(Yes, I am taking notes in objective-c comment format.)

0
source

All Articles