Possible Duplicate:
How does an underscore in front of a variable in a cocoa objective-c class work?
I'm using the same convention for instance variable and properties naming as shown by sebnow in his following answer:
instance variable/ method argument naming in Objective C
I copy paste his example code here:
@interface Foo : NSObject {
id _bar;
}
@property (nonatomic, retain) id bar;
- (id) initWithBar:(id)aBar;
@end
@implementation Foo
@synthesize bar = _bar;
- (id) initWithBar:(id)aBar {
self = [super init];
if(self != nil) {
_bar = aBar;
}
return self;
}
@end
In the implementation of some methods of the Foo class, I use for example:
_bar = aBar
instead of using:
bar = aBar
The 'Analyse' tool introduced by Xcode 4 gives me this warning (I'm using version 4.0.2):
Instance variable 'bar' in class 'Foo' is never used by the methods in its @implementation (although it may be used by category methods)
Perhaps I should use:
self.bar = aBar
But for the readonly properties, that can't work, and beside that, I'm not sure if using the setter in the class itself is a good practice or not.
I'm not fresh in Objective-C, but I'm still in the beginning of learning. Perhaps I'm doing something wrong, and have a bad coding practice somewhere.
Thanks you in advance if you can help me ;)