CoreData merge conflict shows managed object version change not data
<p>I am have an entity in core data and I try to update it from two different context. I am storing managedObjectID of my managed object which I need to update as it is thread safe. Before updating my object I refresh the object to avoid merge conflict. Here is my code:</p>

<pre><code>context1.performBlock {
    let myObject = context1.objectWithID(managedObjectId)
    context1.refreshObject(myObject, mergeChanges: true)
    myObject.property1 = newValue
}
</code></pre>

<p>Notice that I haven't saved the context here, as I want to commit these changes as part of transaction with other updates.</p>

<p>For the same object I have some other properties which I need to commit straight away, so I create separate context for that to prevent property1 to get committed immediately.</p>

<pre><code>context2.performBlock {
    let myObject = context2.objectWithID(managedObjectId)
    context2.refreshObject(myObject, mergeChanges: true)
    myObject.property2 = newValue
    do {
        try context2.save()
    }
    catch {}
}
</code></pre>

<p>In above code, on <code>context2</code>, I have updated <code>property2</code>, which will be committed to db immediately but this is not so frequent update in my case. On <code>context1</code> I am updating <code>property1</code> frequently (in every1 sec), and I commit it in every 10 seconds (notice that every time I update <code>property1</code>, I refresh object, so I will get updated value of <code>property2</code> once changed by <code>context2</code>).</p>

<p>This works fine for most of the time, but some times I get merge conflict. I don't know why I am getting merge conflict even after refreshing object every time.</p>

<p>Also my console shows me same object except version of managed object, so if all properties are same than how version got updated?</p>

<p>Console log:</p>

<blockquote>
  <p>Error Domain=NSCocoaErrorDomain Code=133020 "Could not merge changes." UserInfo={conflictList=(
      "NSMergeConflict (0x17fa78f0) for NSManagedObject (0x18751830) with objectID '0x170f1ca0' with oldVersion = 8 and newVersion = 9 and old object snapshot = <strong>{\n    property1 = value1;\n    property2 = value2\n}</strong> and new cached row = <strong>{\n    property1 = value1;\n    property2 = value2\n}</strong>"
  )}</p>
</blockquote>

<p>As you can see, older object snapshot and new cached row has same data, but version is different.</p>