Suppose I declare a property like so
@property (nonatomic, copy) NSObject *property;
Then I create a custom setter method
- (void) setProperty:(NSObject *)property
{
_property = property;
// Some more code here
}
Does the compiler interpret the copy
keyword so that this setter function is equivalent to this?
_property = [property copy];
Or is it my responsibility to write it this way so that the keyword matches the behavior?
From "4.1.1 Property declarations" in the Clang/ARC documentation (emphasis added):
So in your case, with a custom setter, declaring the property as "copy" implies that the associated instance variable
_property
is__strong
but nothing else.It is your responsibility that the setter actually makes a copy, for example: