title: Instance variables with underscore in Objective-C 2.0 and renaming with @synthetize leads to optimization warnings by the 'Analyze' tool of Xcode 4
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/822487/how-does-an-underscore-in-front-of-a-variable-in-a-cocoa-objective-c-class-work">How does an underscore in front of a variable in a cocoa objective-c class work?</a>  </p>
  </blockquote>
  
  
  
  <p>I'm using the same convention for instance variable and properties naming as shown by sebnow in his following answer:</p>
  
  <p><a href="https://stackoverflow.com/questions/549962/instance-variable-method-argument-naming-in-objective-c/550410#550410">instance variable/ method argument naming in Objective C</a></p>
  
  <p>I copy paste his example code here:</p>
  
  <pre><code>@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
  </code></pre>
  
  <p>In the implementation of some methods of the Foo class, I use for example:</p>
  
  <pre><code>_bar = aBar
  </code></pre>
  
  <p>instead of using:</p>
  
  <pre><code>bar = aBar
  </code></pre>
  
  <p>The 'Analyse' tool introduced by Xcode 4 gives me this warning (I'm using version 4.0.2):</p>
  
  <p><strong>Instance variable 'bar' in class 'Foo' is never used by the methods in its @implementation (although it may be used by category methods)</strong></p>
  
  <p>Perhaps I should use:</p>
  
  <pre><code>self.bar = aBar
  </code></pre>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <p>Thanks you in advance if you can help me ;)</p>