-2

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

rmaddy
  • 307,833
  • 40
  • 508
  • 550
toshi0383
  • 386
  • 1
  • 2
  • 11

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
  • 697,062
  • 78
  • 1,055
  • 1,465