I'm deleting all objects from my Model, except certain objects which the user has interacted with.
After deleting I fetch those saved objects and update their information, from a JSON, and when I save the managedContext the app crashes printing 'Unable to recover from optimistic locking failure.'
I've been looking but I haven`t found any information on what this message means, any idea?
Thanks.
Google first result, documentation from Apple. (Where exactly have you been "looking"?)
Problem: You see the error message, "Could not merge changes".
Cause: Two different managed object contexts tried to change the same data. This is also known as an optimistic locking failure.
Remedy: Either set a merge policy on the context, or manually (programmatically) resolve the failure. You can retrieve the currently committed values for an object using committedValuesForKeys:, and you can re-fault the object (so that when it is next accessed its data values are retrieved from its persistent store) using refreshObject:mergeChanges:.
Even though the error message is different, this sounds very much like your case, for you most likely have multiple contexts that try to modify the same objects.
Try setting the merge policy to NSMergeByPropertyObjectTrumpMergePolicyType
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With