Search code examples
iosobjective-censembles

Should I avoid saving to persistent store while Ensembles is merging?


I'm currently implementing Core Data sync using Ensembles, and I was wondering if I should prevent users from saving to Core Data while CDEPersistentStoreEnsemble is merging?

I am asking this due to the method documentation of mergeWithCompletion:

A merge can fail for a variety of reasons, from file downloads being incomplete, to the merge being interrupted by a save to the persistent store. Errors during merging are not typically very serious, and you should just retry the merge a bit later. Error codes can be found in CDEDefines.

-(void)mergeWithCompletion:(CDECompletionBlock)completion;


Solution

  • It is not necessary to avoid saves during merges, but it may be an idea to avoid non-essential saves. An essential save is one that happens on termination, or going to the background, where you may not get another chance to save the data.

    For less important saves, you could check the isMergjng flag and skip the save.

    Note that nothing bad will happen if a merge gets interrupted by a save, and sometimes it is unavoidable. The merge will fail, but the next merge should work fine.