In most tutorials, the way to declare instance variable is to put it in .h
@interface myViewController: UIViewController {
UITextField *myTextField;
}
@property (nonatomic, retain) IBOutlet UITextField *myTextField;
and in .m
@implementation myViewController
@synthetize myTextField;
But in this standford University course http://itunes.apple.com/itunes-u/ipad-iphone-application-development/id480479762 the way to do so is rather
In .h do only:
@interface myViewController: UIViewController
@property (nonatomic, retain) IBOutlet UITextField *myTextField;
In .m do this:
@synthetize myTextField = _myTextField;
Are they equivalent ? Is the second method specific to iOS5 ?
They are functionally equivalent. In ObjC 2.0 the
synthesize
keyword will automatically create the associated ivar if you do not specify one as part of thesynthesize
statement. This functionality is present on all modern runtimes.