简体   繁体   中英

Debugging @property / ivar values

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)

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM