Volodymyr Volodymyr - 1 month ago 6
Objective-C Question

What's called when copying a property

When we have property with memory identifier

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

Answer

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.