I saw this code snippet on the Internet (http://iphonedevelopment.blogspot.com/2008/12/outlets-property-vs-instance-variable.html):
#import <UIKit/UIKit.h>
@interface MyViewController : UIViewController {
UILabel *myLabel;
}
@property (nonatomic, retain) IBOutlet UILabel *myLabel;
@end
My question is…When @synthesize is called isn’t the UILabel instance variable created automatically? What is the point of creating the instance variable in the header file.. Can you get away with just the @property?
Yes.
Personal preference. Some developers (like me) prefer to see a complete picture of the state of a class. It helps to see what instance variables are available, as well as check that all instance variables are released correctly.
It’s also a relatively new feature. Older code wouldn’t expect automatically-generated instance variables.
No, you need to
@synthesizeto get an automatically generated instance variables A property value that’s generated programmatically would not map directly to any instance variable.