Assuming PropertyType
is a pointer to Objective-C object, you could always have written your setter with no checking, like this:
- (void)setProperty:(PropertyType)newValue {
[newValue retain];
PropertyType oldValue = _property;
_property = newValue;
[oldValue release];
}
ARC implements strong assignment exactly like that. Quoting Objective-C Automatic Reference Counting from the clang documentation:
For __strong
objects, the new pointee is first retained; second, the lvalue is loaded with primitive semantics; third, the new pointee is stored into the lvalue with primitive semantics; and finally, the old pointee is released. This is not performed atomically; external synchronization must be used to make this safe in the face of concurrent loads and stores.
Thus we can deduce that, under ARC, you can implement a property setter with a simple assignment and no checking:
- (void)setProperty:(PropertyType)newValue {
_property = newValue;
}