by jazzychad · 15y ago · 0 comments
foo = object.bar;
is syntactic sugar for
foo = [object bar]; //where 'bar' is a method call
and object.foo = bar;
is syntactic sugar for:
[object setFoo:bar];
I dealt with a lot of goofy memory errors trying to figure out why using 'self.foo' and just 'foo' inside of a class acted differently. Now it makes much more sense.x.foo = z; becomes an ambiguous statement in obj-c when you use dot access. Is x an object? then this is a message send. Is x a struct? then this is an assignment.
Typically in my interface file, I explicitly define my member variables with a leading '_';
@interface Foo { NSObject_bar; }
@property(nonatomic, retain) NSObject
bar;@implementation Foo @synthesize bar=_bar; @end
And if I want to access bar I use [x bar], [x setBar:y]; it is easy to visually scan for direct use of member values by looking for the leading '_'