My app allows a user to edit data, but during save there are two things that can happen:
-
If the name of the data stayed the same, just save the object as an edited version. I.e. they are just editing the existing object.
-
However, if they have changed the name, this should create a new instance and restore the edited data to the original.
Obviously, 1 is the easy case and is working just fine. But I’m conflicted about the best method to handle 2. How best is it to save a modified NSManagedObject as a new row in the DB?
There is no obvious way to just “copy” a
NSManagedObject. The most robust way is to simply recreate everything from scratch.Make sure you have all the changed attributes stored separately (here I am assuming they are in various text fields or that they are unchanged from the existing object). You can make this decision (new instance or not) when your editing view controller is dismissed: