JMD
JMD

Reputation: 1590

copy NSManagedObject to a new object in memory

I have a menu screen that populates with data from an NSManagedObject. While this screen is up the user can enter in all sorts of values. etc.

The problem I am having is that I need to not alter the initial NSManagedObject used to populate the screen. I need a copy that the user can alter instead because if they cancel out before everything is done, then what was the original and correct information gets corrupt by impartial data.

However, I am having issues implementing any kind of copy method or process inside my NSManagedObject because all of the properties are @dynamic.

If I just 'return self' in a copyWithZone method inside the NSManagedObject, would that properly copy everything?

Upvotes: 0

Views: 511

Answers (2)

Anurag
Anurag

Reputation: 36

Why not use a category to add a copy method to your custom NSManagedObject?

If your NSManagedObject was User, then create a new category User+copy.h/m where in you would add the copy method which would simply copy all the individual fields one by one.

Upvotes: 1

Tim
Tim

Reputation: 60130

What you want is to make your changes to the same NSManagedObject, but in a child NSManagedObjectContext. That way, if you need to discard the changes, you can just throw the child context away without affecting your main context or object. See this question.

Upvotes: 1

Related Questions