Property declaration help [duplicate]
Possible Duplicate:
How does an underscore in front of a variable in a cocoa objective-c class work?
I have seen many online examples where they use the following coding style for property declaration:
@interface Book : NSObject
{
NSString *_title;
}
@property (nonatomic, retain) NSString *title;
@end
In implementation:
@implementation Book
@synthesize title = _title;
@end
Question is why we are using underscore?
Solution 1:
If you use an underscore convention you can know at a glance if code is using a property or a class member variable within class methods. There's no technical reason for this, it's personal preference. Depending on what you are doing it can be helpful. It's certainly not necessary if you choose not to do it.
Solution 2:
Underscores are used just to be sure that you won't overlap method names, so if you are safe in naming of your variables you don't need to