iosobjective-ccocoacocoa-touchcopy

Copy custom class object


I have a custom class which has got some properties. And I want to copy an object of this class so I get second object with the same content.
Example:

MyCustomClass *objectName = [[MyCustomClass alloc] init];
// fill here with some properties
objectName.propertyOne = @"smth";
objectName.propertyTwo = @"smth";
// And copy my object
MyCustomClass *secontObject = [objectName copy];

Does there exist something like "copy" method?

Note: the real copy method which is already built in didn't help.


Solution

  • There is nothing built in. The NSCopying protocol is included for this, but since it's just a protocol, you have to implement the copying logic yourself.