Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is conflict in NSManagedObject and what's the different between some of the merge Policy?

NSMergeByPropertyObjectTrumpMergePolicy and NSOverwriteMergePolicy is the same in one thing. The property overwrite the one in the store.

So what's the different between them? In all cases I can think of, whether the one in persistent store have changed or not, the property override the persistent store.

Also what is conflict?

I thought conflict simply means that the data are different. Does this mean that core data is originally designed that once data is written it cannot be updated?

If conflict is something different than mere "data different", then what's the difference between NSOverwriteMergePolicy and NSErrorMergePolicy?

In both cases, mere data difference is not a conflict anyway and hence there can't be a conflict.

like image 395
user4951 Avatar asked Jan 25 '13 05:01

user4951


People also ask

What is the difference between >>== and new_branch_for_merge_conflict?

The ======= line is the “center” of the conflict. All the content between the center and the <<<<<<< HEAD line is content that exists in the current branch master which the HEAD ref is pointing to. Alternatively, all content between the center and >>>>>>> new_branch_for_merge_conflict is content that is present in our merging branch.

How do I resolve a merge conflict in Git?

There are three ways to resolve a merge conflict in Git: 1. Accept the local version. To accept all changes on a file from the local version, run: git checkout --ours <file name>. Alternatively, to accept the local version for all conflicting files, use: git merge --strategy-option ours.

How do I prevent merge conflicts?

Merge conflicts only happen when the computer is not able to resolve the problem automatically. Here are some tips on how to prevent merge conflicts: Use a new file instead of an existing one whenever possible. Avoid adding changes at the end of the file.

What is a removed file merge conflict?

In removed file merge conflicts, a dev deletes a file in one branch while another dev edits the same file in another branch. In this case, you need to decide if you want to keep the file or if it was right to delete it. What's Next?


1 Answers

Does this mean that core data is originally designed that once data is written it cannot be updated?

No. It wouldn't be much use if that was the case, would it?

Also what is conflict?

In Core Data a conflict can occur when you have more than one managed object context (MOC) accessing the same data store. This is common in multithreaded apps. Each MOC can save changes independently of the other. But you want to keep a consistent view of the data across all threads, so it's possible to be notified that changes have been saved on one MOC and merge those changes into a different context. That keeps the contexts in sync.

But what if you try to merge changes into a MOC, and it has different unsaved changes to the same data? Like, both MOCs changed the same attribute on the same instance, and they changed it to different values. This is when a conflict occurs. If you try to merge changes, the results depend on the MOC's merge policy. By default it uses NSErrorMergePolicy, which means that the merge fails and your code needs to sort out and resolve the conflict somehow. There are several built-in merge policies that apply different automatic resolution schemes to the conflict.

The four built in resolution schemes give priority to either the changes on disk or to changes in memory. They differ also in how they handle non-conflicting in-memory changes. For example, NSMergeByPropertyStoreTrumpMergePolicy updates any conflicting changes in memory to match the changes from the other MOC, but leaves non-conflicting changes in place. NSRollbackMergePolicy differs in that it completely discards in-memory changes, even if they don't conflict with new changes from the other MOC. You can also create your own merge policies if none of the built-in schemes seems right.

In both cases, mere data difference is not a conflict anyway and hence there can't be a conflict.

There most certainly can be conflicts. It's a very common scenario.

like image 159
Tom Harrington Avatar answered Oct 10 '22 07:10

Tom Harrington