Flying_Banana
Flying_Banana

Reputation: 2910

What does "->" mean in objective-c?

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.

Upvotes: 0

Views: 68

Answers (1)

Josh Engelsma
Josh Engelsma

Reputation: 2646

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 ->

Upvotes: 3

Related Questions