But in Objective-C is there any difference between self.myivar and self->myivar?
Yes, there's a difference. Assuming that foo
is a pointer to an object:
foo->bar
is equivalent to (*foo).bar
where the dot indicates the member access operator to get the instance variable bar
.
foo.bar
is equivalent to [foo bar]
; that is, it sends the message -bar
to the object pointed to by foo
. That may just return whatever is in foo
's bar
instance variable, but it may do other things. There may not even be an instance variable named bar
. As long as there's a method called -bar
, however, foo.bar
is valid. There should also be a -setBar:
method if you're using foo.bar
as the left hand side of an assignment, like: foo.bar = baz;
.
Note that although self
is a keyword in Objective-C, it always acts as a pointer to an object. There's nothing special about self
with respect to accessing properties or instance variables. I've used foo
as the name of the object pointer above to demonstrate that property/ivar access works the same way for any object pointer, but you could substitute self
for foo
above.