0

Well, I'm sorry I can't find any useful results when I search "->" on Google, and this is the first time I've seen anything like this. I've found the following line in one of Ray Wenderlich's game center tutorials:

Message *message = (Message *)[data bytes];
if (message->messageType == kMessageTypeRandomNumber) {
    ...
}

Message here is a predefined struct:

typedef struct {
    MessageType messageType;
} Message;

From http://www.raywenderlich.com/3325/game-center-tutorial-for-ios-how-to-make-a-simple-multiplayer-game-part-22.

Flying_Banana
  • 2,864
  • 2
  • 22
  • 38

1 Answers1

3

This means the same thing as it does in C and C++, basically you are accessing the data of a pointer.

If you were using an object: you might say message.messageType

Since you are dealing with a pointer: you use message->messageType to get the messageType data from the pointer message

This syntax saves you from having to dereference a variable before you access its data.

Here is a link to another StackOverFlow question which was asked from a programmer learning C. The same content/principles apply here. Arrow Operator

Here is another link explaining the Difference Between . and ->

Community
  • 1
  • 1
Josh Engelsma
  • 2,636
  • 14
  • 17
  • 1
    ... so the number one use for `->` nowadays is probably accessing unexposed member variables on a variant of `self` that has been deliberately kept weak and then made strong again for the benefit of an asynchronous block. – Tommy Mar 22 '14 at 03:18