drewmccormack / ensembles

A synchronization framework for Core Data.
MIT License
1.63k stars 132 forks source link

didSaveMergeChangesWith callback never called #279

Closed timbuchwaldt closed 5 years ago

timbuchwaldt commented 5 years ago

Hey! I'm having a similar issue as @tjosten in #277 - I see all baselines/events appearing in my app, even ensemble:shouldSaveMergedChangesIn:... is being called but I never see ensemble:didSaveMergeChangesWith being called. Also there is no data actually appearing in my NSPersistentContainer-managed CoreData.

Can you give me any hint what to try/debug?

drewmccormack commented 5 years ago

That is very odd. And you are returning 'true' from the should-save-merge-changes? You aren't releasing the ensembles object somewhere?

timbuchwaldt commented 5 years ago

Wow that was a quick reply :D I returned true there, now commented out the implementation to check whether that changes anything (it doesn't).

Pretty sure I'm not releasing it, I hold a reference from my AppDelegate to the object - I also see logs appearing from CDECloudManager and all that - just never actually merging.

drewmccormack commented 5 years ago

So the completion block of the merge method is never called? Is it possible perhaps that the did-merge isn't called, because it discovers there were no changes in the sync data. I think that can happen. The completion block should always be called though, data or no data.

If the merge is completing, but you don't see any data, the most likely culprit is simply that iCloud Drive has not yet transferred the data over. When using the simulator, you might need to use the Debug menu in Xcode to trigger the transfers.

timbuchwaldt commented 5 years ago

Having lunch + trying again worked. I actually found an Ensembles error 204 (wrong model version) hiding in the log -> Wiped iCloud drive & restarted apps -> Working.

Thanks a bunch :)

timbuchwaldt commented 5 years ago

For future reference: Be sure to implement didFailToSaveMergedChangesIn as it might get called, like in my case, with a nice error: I had a unique constraint that failed and prevented almost all merges, just in some cases it seems to have merged it when I reset stuff and had the timing just right that recreated it.

@drewmccormack As I think I haven't seen the error without implementing the callback: Might it be useful to provide a default implementation for this that logs this error very prominently?

func persistentStoreEnsemble(_ ensemble: CDEPersistentStoreEnsemble!, didFailToSaveMergedChangesIn savingContext: NSManagedObjectContext!, error: Error!, reparationManagedObjectContext reparationContext: NSManagedObjectContext!) -> Bool {
    print("Merge failed \(error)")
    return false
}
drewmccormack commented 5 years ago

Isn’t there any error in the merge completion block? I would expect the merge should fail.

Drew

On 24 Sep 2018, at 10:11, Tim Buchwaldt notifications@github.com wrote:

For future reference: Be sure to implement didFailToSaveMergedChangesIn as it might get called, like in my case, with a nice error: I had a unique constraint that failed and prevented almost all merges, just in some cases it seems to have merged it when I reset stuff and had the timing just right that recreated it.

@drewmccormack As I think I haven't seen the error without implementing the callback: Might it be useful to provide a default implementation for this that logs this error very prominently?

func persistentStoreEnsemble(_ ensemble: CDEPersistentStoreEnsemble!, didFailToSaveMergedChangesIn savingContext: NSManagedObjectContext!, error: Error!, reparationManagedObjectContext reparationContext: NSManagedObjectContext!) -> Bool { print("Merge failed (error)") return false } — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.