CloudKit - Conflict Resolution with counters

If one offline device increments a counter (starting at 0) value by 5 and a second offline device decrements the counter by 2, what can I do so that the final counter value is 3 (once the devices come back online)?

I have read about operational transformations for conflict resolution. Is there any example code I can look at that implements it?

Answered by ForumsContributor in
Accepted Answer

Operational transforms that model scalar values are typically implemented by collections of contributions (the operations). For example a vector or array of integers that represent the value.

The implementations are necessarily aligned with application requirements like language, technology stack, supported distributed systems primitives etc. With NSPersistentCloudKitContainer such a counter is trivially implemented using a one-to-many or many-to-many relationship that joins the transformations to the root entity.

If you have specific questions about that we are happy to help, but will require a little more context like your model and desired contribution structure.

CloudKit - Conflict Resolution with counters
 
 
Q