Search code examples
objective-cios5nskeyedarchivernscopying

Getting error when trying to modify a property of a nscopied object


I've created a model that has mainly a nested array of custom objects for use in a split-view (both UITableViews) "to-do" list type app. The left (master) is the lists of lists and the right (detail) is the lists :) Some other variables are kept in some of the classes like isSelected, isExpanded...

All of these classes implement NSCopying protocol. When I make a copy of a master list item and change the copy's name that works, but if I change anything in the detail list item belonging to that master list item, it changes in both the copy and the original. So I guess my question is how do I create a deep copy of a master list item. I thought by making them all implement NSCopying protocol it would automatically do this. I I really don't know what to put for code with so anything you need just ask.


Solution

  • Take a look at NSKeyedArchiver - you can archive your array of arrays, unarchive it, and you have a deep copied clone.

    (Of course this only works if all your objects support archiving.)