Objective C instance variables - Newbie
- by Dwayne King
OK - so 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.
In Java, I can declare a variable in a class, like this, and each instance of that class will have it's own:
MyClass {
String myVar;
MyClass() {
// constructor
}
}
In Obj C I tried to do the same thing by declaring a variable only in the .m file like this:
#import "MyClass.h"
@implementation MyClass
NSString *testVar;
@end
My expectation here was that this variable has a scope limited to this class. So I created a second class (identical):
#import "MySecondClass.h"
@implementation MySecondClass
NSString *testVar;
@end
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
I've created an extremely small XCode project that demonstrates the problem here
Nothing more humbling than moving to a new language :)
Thanks in advance.