I'm coming from Ruby to Objective-C and I keep doing:
NSObject *foo;
@property (nonatomic,retain) NSObject *foo;
in the .h file, and then in .m file:
@synthesize foo;
at the top and
[foo release]
in dealloc.
It's 4 steps to add foo
! Do seasoned Objective-C programmers do all four steps manually each and every time they want to add a new instance variable to a class? Am I missing a way to make this DRY?
This is a common concern in C++ as well (doubling up of declarations, though it is admittedly a little different). The short answer is that it is how the language is constructed. It's doesn't really go against DRY since each statement is unique and has its own purpose. However it is admittedly very verbose by today's standards.
This page http://pragprog.com/magazines/2010-07/not-quite-new-in-ios- claims, that you can drop the variable declaration, bringing it down to 2 repeats only :)
#import <UIKit/UIKit.h>
@interface MoveMeViewController : UIViewController {
}
@property(nonatomic, retain) IBOutlet UIImageView *imageView;
@end
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