Property Ad Help

Possible duplicate:
How is the underscore in front of a variable in the cocoa objective-c class?

I have seen many online examples where they use the following coding style to declare a property:

@interface Book : NSObject { NSString *_title; } @property (nonatomic, retain) NSString *title; @end 

In implementation:

 @implementation Book @synthesize title = _title; @end 

Question: why do we use the underscore?

+1
source share
2 answers

If you use the underscore convention, you can immediately see if the code uses a property or member variable of a class in class methods. There is no technical reason for this; it is a personal preference. Depending on what you do, this may be helpful. It is not necessary if you decide not to.

+2
source

The underscores are used only to ensure that you will not overlap method names, so if you are safe in naming your variables, you don’t need to

+1
source

All Articles