Comming from a C++ part of me says to always use the acessors if
defined (unless private and not exposed), also using the accessors
allows us to make sure our bindings are updated if its a bound
value, but i see a mix of code and it may depend on if the iVar is
to be exposed or not.. The company i work for is now getting into
iPhone and 10.5 development and i want to stress the proper design
choices.
As with the others who replied, I agree. In fact, if an instance
variable contains accessor methods, then I use a naming convention
(in my case, an "a_" prefix, for "accessor") to indicate that fact,
which allows me to easily spot those locations in my code where I
accidentally refer directly to the instance variable. This is
particularly important when you are using key-value observing, as
assigning directly to an instance variable will not notify anyone
observing it.
In your case, that would mean:
@interface foo : NSObject
{
@private
NSString* a_myString;
}
@property(copy) myString;
-(void)displayString;
@end
@implementation foo
@synthesize myString = a_myString;
@end
I find that in a flexible language like Obj. C (and I am not
complaining about that flexibility!), such informal conventions go a
long way towards preventing silly errors that other languages might
prevent with new keywords and the like.
Niko