1

Possible Duplicate:
How does an underscore in front of a variable in a cocoa objective-c class work?
Why rename synthesized properties in iOS with leading underscores?

I am a green hand in iOS programming.

I always see such a statement in other's code

@synthesize textNoteOrLink = _textNoteOrLink;

What is the meaning of the underline anyway? Can we just 'textNoteOrLink' in that case.

Community
  • 1
  • 1
Dragon warrior
  • 1,644
  • 2
  • 24
  • 37
  • 2
    its an underscore and is used to differentiate the instance variable from the property: http://stackoverflow.com/questions/5466496/why-rename-synthesized-properties-in-ios-with-leading-underscores – wattson12 Oct 08 '12 at 21:42

1 Answers1

4

Yes you can just write textNoteOrLink.

Many developers put an underscore at the start of instance variable names (@synthesizing a property actually adds an ivar for that property) to avoid accidentally using the ivars instead of the property, bypassing setters and getters.

IMHO it's a good thing to do, but if you don't like it, just don't use it, but be cautions not to confuse properties and ivars.

Ahti
  • 1,420
  • 1
  • 11
  • 20
  • Yes. It is just like prefixing a variable with m or g in C++ to indicate member or global respectively. The underscore separates the property from the iVar that contains its value. – vagrant Oct 08 '12 at 21:47
  • just for beginners: IVAR stands for instance variable :-) – andilabs Apr 22 '13 at 23:05