I have a problem understanding properties.
What kind of property should I write if I want an attribute not be modified by its accessors (return by copy) and be set by reference (retain).
Example :
MyType* theAttribute = MyObject.attribute;
[theAttribute changeSomething]; // Does not have to change the MyObject attribute, working with a copy return
MyType tmpObject = [[MyType alloc] init];
MyObject.attribute = tmpObject; // Want a retain here
[tmpObject release];
declare the property as retain in the header:
In the implementation file synthesize the iVar:
But provide your own getter which will override the synthesized one:
I know I’m not autoreleasing the returned object, but since the question doesn’t specify iOS, I’m writing this from the perspective of a garbage collected environment.