Now with the release of the new Xcode it has been said that properties get synthesized automatically, and indeed they are accessible without synthesizing as long as you use the '_' prefix. But I recently found out that Xcode allows me to access those properties in another way – using a 'self.*' prefix (where the * is the name of the property).
Is this correct? Should I use it? Could it harm my code?
Thanks you.
With
_yourPropertyyou access the instance variable, withself.yourPropertyits getter/setter. As long you are sure you have no costumized getter/setter, both is the same (with a very small performance penalty for getter/setter). However, in general, you should use the getter/setter approach (except in getter/setter themself) in case you will change your code later.EDIT:
@Vanthel: The underline is pure convention. Without
@synthesize(or with@synthesize foo), the compiler generates for a propertyfooa variable_foo. However, by@synthesize foo = my_baryou assign the variablemy_barto be accessed by the accessors offoo.