title: iOS - beginning iOS tutorial - underscore before variable?
body: <p>I am starting to learn how some iOS development at the minute and I currently have the Apress beginning IOS6 book that I am working off.</p>
  
  <p>In chapter two there is a simple tutorial to show two buttons and a label and when a button is pressed it is shown on the label which one was pressed.</p>
  
  <p>I have completed the tutorial but it has raised one question that I can't find the answer to.</p>
  
  <p>The tutorial uses ARC (automatic reference counting) in case that makes a difference. </p>
  
  <p>Here is the code,</p>
  
  <p>The header file:</p>
  
  <pre><code>#import &lt;UIKit/UIKit.h&gt;
  
  @interface MTMViewController : UIViewController
  
  
  @property (weak, nonatomic) IBOutlet UILabel *statusLabel;
  
  
  - (IBAction)buttonPressed:(UIButton *)sender;
  
  @end
  </code></pre>
  
  <p>And the m file:</p>
  
  <pre><code>#import "MTMViewController.h"    
  
  @implementation MTMViewController
  
  - (IBAction)buttonPressed:(UIButton *)sender {
  
  
      NSString *title = [sender titleForState:UIControlStateNormal];
  
      NSString *plainText = [NSString stringWithFormat:@"%@ button pressed.", title];
  
      statusLabel.text = plainText;
  
  
  }
  
  @end
  </code></pre>
  
  <p>The above is how it appears in the book, however when doing the tutorial in Xcode I could not compile with the following line:</p>
  
  <pre><code>statusLabel.text = plainText;
  </code></pre>
  
  <p>And instead had to change it to:</p>
  
  <pre><code>_statusLabel.text = plainText;
  </code></pre>
  
  <p>When I done this the code compiled and ran fine, I tried to figure out why this happened by going back through the tutorial to see if I missed anything but I didn't see anything.</p>
  
  <p>Can anyone explain why the code in the book didn't compile and why I had to add the underscore to the front of the variable? Is this correct or have I done something wrong?</p>