Possible Duplicate:
Synthesized property and variable with underscore prefix: what does this mean?
The usage of Objective-C properties has always felt awkward to me. It's one of the "I know how to use them, but I'm not always sure why I'm using them." kind of things and recently I've been seeing a lot of this:
// in .h file
@interface MyObject : NSObject
{
id _coolIvar;
}
@property (assign) id coolIvar;
@end
// in .m file
@implementation
@synthesize coolIvar = _coolIvar;// <- whats the point of that.
@end
So what is the point of declaring an ivar with an underscore and then using @synthesize to access it, Opposed to just declaring the @property with the same name as the ivar?
Side Question: I've noticed that this convention has been becoming increasingly more popular since blocks started becoming the preferred approach for async callbacks opposed to the target/selector approach. Is that a coincidence or does the above @property declaration convention play nicer with block scopes?