Possible Duplicate:
Difference between self.ivar and ivar?
I wonder, if I define an instance variable as property in Obj-C, for example,
@property (copy) NSString *str;
and
@synthesize str = _str;
should I access it within the instance methods by
_str = @"ABC";
or should I use the accessor, that is
[self setStr:@"ABC"];
Is there any general guideline regarding this?
Thanks very much!
It’s okay to read the instance variable from inside the class:
But don’t set the instance variable directly:
This bypasses the
copymechanism you’ve so carefully placed on your property. So do it this way instead: