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?
operator is used to access a member of a struct, while the arrow operator ( -> ) in C is used to access a member of a struct which is referenced by the pointer in question.
The -> (arrow) operator is used to access class, structure or union members using a pointer. A postfix expression, followed by an -> (arrow) operator, followed by a possibly qualified identifier or a pseudo-destructor name, designates a member of the object to which the pointer points.
Arrow operator on an Objective-C object (pointer) (at run time) Dereference pointer. Return value of the field.
The -> is called the arrow operator. It is formed by using the minus sign followed by a greater than sign. Simply saying: To access members of a structure, use the dot operator. To access members of a structure through a pointer, use the arrow operator. cpp_operators.htm.
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);
free(p);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With