Reputation: 153
If you define a pointer as a @property
and also as an instance variable in the @interface
, does that generate two versions of the same variable ? Should you do either one or the other ?
I am programmatically trying to create an UIImageView
and display it in a new instance of a UIWindow
, and I'm using the debugger to check the values to see why it doesn't work.
If I just define the UIWindow *
as a @property
and not as an ivar, it doesn't appear in the debugger data window, but printf gives it's value as 0x6D4CD00.
If I define it as both a @property
and an ivar then I can see it in the debugger but it's 0x0 and printf still says 0x6D4CD00.
Are they two different variables ?
Why can't I see the @property
in the debugger ? (iPhone simulator) + (ARC=on)
Upvotes: 1
Views: 271
Reputation: 2860
Agree with @nikolai-ruhe that there's no code reason to explicitly declare instance variables, but it can be helpful to have immediate access in the debugger (via spinning down self
) to see the contents of those variables. Entirely an opinion thing though; you can always introspect with po [self valueForKey:@"variableName"]
too.
Upvotes: 1
Reputation: 81868
Declaring properties using the keyword @property
does not create any instance variable. It's the @synthesize
directive that connects a property to a variable.
The name of the instance variable is either explicitly specified via the @synthesize foo = _foo
notation or, by default, the property's name itself.
The @synthesize
directive can either connect an explicitly declared instance variable to the property, or, if there's no variable with the property's identifier, create one implicitly.
There's usually no reason to explicitly declare instance variables.
Upvotes: 2