-2

What does objc's -> stand for ?
Is there any difference from just dot chain?
e.g. self.delegate , self->delegate

rmaddy
  • 314,917
  • 42
  • 532
  • 579
toshi0383
  • 396
  • 1
  • 2
  • 12

1 Answers1

2

-> in Objective-C is the same as -> in C. It is a field access operator that lets you dereference a pointer (as opposed to dot . operator, which requires a struct).

What's confusing about it in Objective-C is the dot syntax on pointers for accessing properties. So the rules for choosing a dot vs. -> become a little confusing:

  • Use dot . for accessing Objective-C properties on Objective-C objects, which are always accessed through pointers
  • Use arrow -> for accessing Objective-C instance variables on Objective-C objects, and for accessing fields on C structures through pointers
  • Use dot . for accessing fields on C structures.
Sergey Kalinichenko
  • 714,442
  • 84
  • 1,110
  • 1,523