Assume we have a class Foo with a property bar.
Declared like this in the header:
@interface Foo : NSObject {
int bar;
}
@property (nonatomic, assign) int bar;
@end
In the .m I have @synthesize bar; of course.
Now, my question is, if I remove the int bar; line, the property behaves the same way, so, is that line really necessary? Am I missing some fundamental concept?
Thanks!
The "modern" Objective-C runtime generates ivars automatically if they don't already exist when it encounters@synthesize.
Advantages to skipping them:
@property gives the type, name and use (a property!) of the ivar, so you're not losing anything.There are a few caveats:
Because of the debugger issue, at the moment I explicitly add all my ivars and flag them like this:
@interface Foo : NSObject {
#ifndef SYNTHESIZED_IVARS
int ivar;
#endif
}
@property (nonatomic, assign) int bar;
@end
My plan is to remove that block when I've confirmed the debugger is able to show the ivars. (For all I know, this has already happened.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With