I’m really confused about using proprieties.
if i declare this
@property (nonatomic, strong) NSString* aString;
what is the difference between this
1.@synthesize aString = _aString
and
2.@synthesize aString;
if i want to use it, what is the difference between:
3. anOtherString = aString;
and
4. anOtherString = self.aString;
and
5. anOtherString = _aString;
I know that the _aString is the ivar, but the problem is the combination between 1,2,3,4,5.
for example, if i use 2 and 4, i’m i passing a reference to anOtherString or a copy of it ?
I usually use 2 and 4 is that the best choice for passing a reference ?
Your answer are here :
Ans: Your property name is aString but you are making an alias _aString. Now you can access aString, your accessors can be used by _aString only. From Xcode4.4 onwards this statement comes by default.
Ans: This is the basic style of Objective-c synthesizing a property. From Xcode4.4 onwards this statement overrides the above one.
You are accessing the property by the reference variable/alias.
You are using accessor to get its value.
You are accessing the property itself.
I usually use 2 and 4 is that the best choice for passing a reference ?Ans : This is good way to do, as self. makes your class KVC compliant.