Possible Duplicate:
Arrow operator (->) usage in C
Dot (“.”) operator and arrow (“->”) operator use in C vs. Objective-C
I’m a newbie looking at a freeware/open-source program last updated in 2008, and I don’t recognize the -> in the following notation:
- (id)copyWithZone:(NSZone *)zone
{
GFIPGeniusItem * newItem = [[[self class] allocWithZone:zone] init];
newItem->_stringValue = [_stringValue copy];
newItem->_imageURL = [_imageURL copy];
newItem->_webResourceURL = [_webResourceURL copy];
newItem->_speakableStringValue = [_speakableStringValue copy];
newItem->_soundURL = [_soundURL copy];
return newItem;
}
I’m assuming it’s allowing some sort of shortcut, but I’d love to specifically what it does.
In Objective-C you have some kind of two variable type accessors. The one everybody should know is the
"."one (e.g. Class.variable). This type calls either the appropriate getter or setter.Now, the other type – the one you asked for – is for in-class usage. Obviously, as the getter or setter gets called automatically with the
"."notation you need a way to set the variable without a setter (calling the setter in the setter itself results in an endless loop). Therefore, this"->"notation is used -> simply, it is the direct-access mode.Usually, Objective-C the variable name for both notations is the same but some prefer to have the in-class notation variable name beginning with
"_". This is achieved by editing the@synthesize variableline to@synthesize variable = _variable.