Volodymyr Volodymyr - 5 months ago 26
Objective-C Question

What's called when copying a property

When we have property with memory identifier

, what class method will be called by system to copy my object?


An Objective-C property marked as copy will make use of the copy method from the NSObject class. Essentially, the auto-synthesized setter method will look something like this:

- (void)setName:(NSString *)name {
    _name = [name copy];

There's more to it than that (key-value observing, etc.) but what I show covers your question.

If the property is for your own custom class, be sure your class conforms to NSCopying and properly implements the copyWithZone: method.