4

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?

4

1 回答 1

0

所以我对你的主要问题的回答是学术性的,因为我没有用于测试这个的测试库,但是……</p>

鉴于您的目录被视为单个实体,如果您使用该实体作为 NSManagedDocument 操作的项目进行协调。

我将这个答案建立在我学习使用 NSManagedDocument 管理 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).

(是的,我以objective-c 注释格式记笔记。)

于 2013-01-10T20:18:45.860 回答