Difference between accessing property methods and class fields (Objective-C)
objective-c
Solution
There is a big difference. `[self.bar doStuff]` is equivalent to `[[self bar] doStuff]`
`[bar doStuff]` is equivalent to `[self->bar doStuff]`
The former uses the accessor method, the latter just accesses the instance variable bar directly.
If you use the `@synthesize` directive on your `bar` property, the compiler will generate two methods for you:
- (void)setBar:(Bar*)b;
- (Bar*)bar;
Also note, that the compiler generated setter method is retaining your `Bar` instance as you told it in the `@property` declaration.
Problem
Assume that I have this piece of code: ``` @interface Foo : NSObject { Bar *bar; } @property (retain, nonatomic) Bar *bar; @end ``` When using this field/property, is there any difference between lines: ``` [self.bar doStuff]; ``` and ``` [bar doStuff]; ``` ? When doing assignment, property method will perform correct retaining, but what about the read access to the property, as described above? Is there any difference?