Take the 2-minute tour ×

I've seen this operator pop up quite a few times in example code in "Learn Objective C on the Mac."

I believe it's an operator in the C language which Objective C inherits. I tried Googling and searching Stack Overflow and oddly nothing came up.

Does it have an English name?

share|improve this question
add comment

8 Answers

up vote 8 down vote accepted

It has to do with structures.

When we have a struct available locally on the stack, we access its members with the . operator. For example:

CGPoint p = CGPointMake(42,42);
NSLog(@"%f", p.x);

However, if we instead have a pointer to a structure, we have to use the -> operator:

CGPoint *p = malloc(1*sizeof(CGPoint));
p->x = 42.0f;
NSLog(@"%f", p->x);
share|improve this answer
We don't have to, we can use (*p).x instead. –  jer Dec 20 '10 at 1:13
@jer sure, but I'm of the opinion that p->x is a lot simpler to read than (*p).x. –  Dave DeLong Dec 20 '10 at 4:43
add comment

-> is not specific to Objective-C. It's a C operator.

Now that's cleared, it's the member access operator, equivalent to a pointer dereference and then using the dot operator on the result.

Say you had a struct like this:

typedef struct Person {
   char *name;
} Person;

Person *jacob = malloc(1*sizeof(Person));

So this statement:

jacob->name = "Jacob";

Is equivalent to this statement:

(*jacob).name = "Jacob";

Of course, don't forget the free:

share|improve this answer
When you say it is equivalent to *, it isn't really. It is equivalent to dereferencing then accessing using . –  Alexander Rafferty Dec 20 '10 at 0:51
@Mitch, No, I actually meant that. –  Jacob Relkin Dec 20 '10 at 0:53
Perhaps create a Person struct and assign then, for complete correctness. –  Mitch Wheat Dec 20 '10 at 0:54
add comment

In C


is a shortcut for


which is for dereferencing of members of a struct that is pointed to.

This is useful, because of . binds stronger than the dereferencing operator * . So by using -> you avoid having to use these ugly parentheses.

share|improve this answer
add comment

The same thing that it means in C. It can be used to access the instance variables of objects directly, but generally this is not the best practice. The dot notation you're referring to is a property, not the usual C dot notation.

share|improve this answer
It might be interesting to note that self->bla (or plain bla) accesses the ivar directly, while self.bla accesses it through the property accessors. –  Rudy Velthuis Aug 20 '11 at 7:30
Yes, that's kind of implied in my answer. In particular, you can't use self.bla to access an instance variable because self is a pointer to the object in memory. That's why you have to use ->. And that's why there's no conflict between C dot notation and Obj-C properties :) –  jtbandes Aug 20 '11 at 7:31
jtbandes: Exactly. –  Rudy Velthuis Aug 20 '11 at 7:45
add comment

It's a member selection (or access) equivalent to a pointer de-reference (as pointed out in comments)

a->member is equivalent to (*a).member in C/C++

share|improve this answer
As a corollary to the above, it's the same thing as it is in C. –  jer Dec 20 '10 at 0:47
I think that the downvote is because you said that it's a pointer de-reference, while actually the pointer dereference operator is the usual *; the C99 standard calls it "member access operator" as the dot (.) (§6.6.9). I'd just say that it's a shorthand for the (*a).Member notation. –  Matteo Italia Dec 20 '10 at 0:50
+1 because it is correct. –  Alexander Rafferty Dec 20 '10 at 0:50
(Changed Property to member, since Property has a different meaning in Objective-C) –  Dave DeLong Dec 20 '10 at 0:51
@Dave DeLong. Thanks. –  Mitch Wheat Dec 20 '10 at 0:52
add comment

It's the "indirect member access operator". It's a C operator, which both Objective-C and C++ inherited.



is equivalent to:


but is less typing. (The parens are necessary in the expanded form due to precedence of * and ..)

share|improve this answer
add comment

a->b is equivalent to (*a).b, and designates member b of the object pointed to by a.

In the C standard, it is called the "structure/union pointer operator," which isn't really the catchiest name.

share|improve this answer
add comment

It's all been said, it is a shortcut for accessing members of a struct pointer, but just a note to add that you can access ivars using the same syntax due to the way the Objective-C runtime works:

@interface Foo : NSObject {
   NSString *something;

/* ... SNIP ... */

NSLog(@"something = %@", foo->something); // Where foo is an instance of the Foo class

This is handy when you need to access ivars that aren't exposed by methods; specifically when you need to implement copyWithZone: on your objects.

share|improve this answer
thats ok but can you tell me what does this mean. loginViewController->mPortSIPSDK = mPortSIPSDK; first mportSIPSDK is instance of PORTSIPSDK which is declared in loginviewcontroller.Second is ie(=mPortSIPSDK)is declared in aoodelegate. –  suraj k thomas Dec 9 '13 at 6:20
add comment

Your Answer


