4 ms·
it also help when you understand how the dot-notation works in objective-c... it's not like other languages where you are just accessing a member of an object.
by jazzychad 15y ago
it also help when you understand how the dot-notation works in objective-c... it's not like other languages where you are just accessing a member of an object.
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.
- nomurrcy 15y agoA lot of developers (myself included) don't use the dot syntax for property access for this reason and another: 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 '_'