Search code examples
objective-ccore-dataicloud

CoreData + iCloud Sync timing confusing


My question is how to control the timing of CoreData(local database) sync with the iCloud. As I know if I change the local data the iCloud will change automatically. It is possible that iCloud sync data with local until i m ready to?


Solution

  • There is a kind of two step synching. Your local data is put first into a container for synching and then the container is synched with the iCloud. This is done by an demon system-wide. You cannot control that.

    You want to differ between the "local document" and the "cloud document". As mentioned in the comments, this is akin of anti-conceptional. However, there are two strategies to get this. None of them is tested by me.

    1. Do not save the changes you have done in memory.

    2. Add a local version of the store and migrate between the local version and the synched version using migratePersistentStore:toURL:options:withType:error: (NSPersistentStoreCoordinator).

    Both variants have a big disadvantage: If you delay the time to save the (synched) document, potentially the local version and the ubiquitous version run away more and more. This leads potentially to unresolvable conflicts. There is a reason that Apple recommends to save the store as soon and as often as possible (= making it public). BTW: Core Data with iCloud synch is no groupware. Do not even try to use it this way.