I think I am missing something about property attributes.
First, I can’t understand the difference between retain and assign.
If I use assign, does the property increase the retain counter by 1 to the setter and also to the getter, and do I need to use release to both of them?
And how does this work with readwrite or copy? From the view of a retain count.
I am trying to understand when i need to use release after working with a property (setter and getter)
@property (readwrite,assign) int iVar;
What does assign do here?
What is the difference between:
@property (readwrite,assign) int iVar;
and
@property (readwrite,retain) int iVar;
and
@property (readwrite) int iVar;
Many thanks…
The setter for
@property (readwrite,assign) sometype aProperty;is semantically equivalent toThe above is more or less what you will get if you put
in your implementation.
The setter for
@property (readwrite,retain) sometype aProperty;is semantically equivalent toClearly, it makes no sense to retain or release an int, so sometype must be either
idorSomeObjectiveCClass*The setter for
@property (readwrite,copy) sometype aProperty;is semantically equivalent toIn this case, not only must sometype be an objective C class but it must respond to
-copyWithZone:(or equivalently, implementNSCopying).If you omit retain or assign or copy, the default is assign.
By the way, I have simplified the above by not considering the locking that occurs because the properties don’t also specify
nonatomic.