In a Navigation based app, I’d like to be able to have a “Clone” or “Save As” button on my detailed Product view where a user can create a new Product from one of their existing products they have already entered. In the app, a product has quite a few attribute fields for the user to enter, so I’d like to offer the ability for a user to quickly “Clone” or “Save As” any of their existing products which would automatically copy the attributes of that existing Product over to a new product and allow the user to enter a name for the new Product and save it.
Any help with how to achieve this would be much appreciated. Thanks.
I’m assuming that you are using Core Data, but you don’t specifically mention that. From the context of your question, that seems to make sense.
Copying properties from one object to another can be tricky. I recommend a great book on Core Data by Marcus Zarra. You can find it here http://pragprog.com/titles/mzcd/core-data
In his book, he runs through this through this scenario except in the context of importing and exporting data, but the code should be similar. Here is some code that is available from his book site (above). This copies all properties, including relationships, from one object to another. You must also identify the name of the parent object in order for it to work properly.
This code will not only copy properties, but also relationships, including related objects and their properties. It works quite well.
Hope this helps!
And this: