If I use @property (save) something * myVar; I can access this variable using self.myVar ... But what is the difference?
@property (retain) Something *myVar; // this property declaration declares: - (Something *)myVar; // and - (void)setMyIvar:(Something *)arg; // and is accessible by dot syntax. // it also declares and/or documents how the ivar is managed (copy, retain, etc.)
in use:
property properties also give instructions to the compiler on how to synthesize an accessor.
Is there a good reason why I should use this or that method?
in init and dealloc, access ivar directly - you are interested in initializing and clearing the ivars object and do not care about subclasses. using properties here can also lead to errors or undefined behavior.
for other cases, that is, when the object is in a fully constructed state, you should always use the accessory for consistency. if a subclass redefines an accessory, ivar direct access may disrupt the design.
if you want to avoid this, make ivar private and not declare a property for it. if you declare a property for it, then document its confidentiality; I usually write @property (retain) Something * private_myIvar;
in this case. in this case it is convenient to use the property for synthseize ivar memory management.
when ivar is private, you have full access to it. safe to handle directly or privately. otherwise, suppose you must use an accessor.
if myIvar is declared private and will only be created upon initialization, you can not declare properties at all. this will reduce run-time overhead (if necessary). Message overhead, save / release cycles, and atomization (naturally) require longer execution times. therefore, it can be bypassed to increase productivity.
visibility / service. sometimes, it is much less maintenance / implementation to hide ivar from the interface. in other cases, ivar is a part of the class implementation and should not be part of the public interface. in such cases, consider making it private (there are several ways to account for this in objc).