title: Objective-C instance variables?
body: <p>I'm sure my confusion here is just a result of being stuck in a "Java mindset" and not understanding how Obj-C differs in this case.</p>
  
  <p>In Java, I can declare a variable in a class, like this, and each <em>instance</em> of that class will have it's own:</p>
  
  <pre><code>MyClass {
  
    String myVar;
  
    MyClass() {
      // constructor
    }
  }
  </code></pre>
  
  <p>In Obj-C I tried to do the same thing by declaring a variable only in the .m file like this:</p>
  
  <pre><code>#import "MyClass.h"
  
  @implementation MyClass
  
  NSString *testVar;
  
  @end
  </code></pre>
  
  <p>My expectation here was that this variable has a scope limited to this class.  So I created a second class (identical):</p>
  
  <pre><code>#import "MySecondClass.h"
  
  @implementation MySecondClass
  
  NSString *testVar;
  
  @end
  </code></pre>
  
  <p>What I'm seeing (and has me baffled) is that changing the variable in one class, affects the value seen in the other class.  In fact, if I set a breakpoint, and then "Jump to Definition" of the variable, it takes me to th</p>
  
  <p>I've created an extremely small Xcode project that demonstrates the problem <a href="https://dl.dropbox.com/u/481022/TestIvar.zip" rel="nofollow noreferrer">here</a>.</p>