I a few simple questions to make sure I am using properties right in my application. I read a lot online but it is still unclear. Thanks a lot for any help or suggestions.
(1) I am not quite sure that the statement does, and why is it needed.
@synthesize personName = _personName;
Why do you need the _personName variable? What is the benefit of doing that as opposed to just creating a property and synthesizing that variable personName.
@property (nonatomic, retain) NSString *personName;
(2) In my application should I be accessing the property variable self.personName or use the _personName variable. I believe the self.personName is correct by then again why is the _personName even there?
(3) Also I am a little confused to which variable I should release in dealloc() and which variable should I set to nil in viewDidLoad(). I also do not know if any changes should be made to the didReceiveMemoryWarning() method.
@interface ViewController : UIViewController
{
NSString *_personName;
}
@property (nonatomic, retain) NSString *personName;
@end
@implementation ViewController
@synthesize personName = _personName;
- (void)viewDidLoad
{
[super viewDidLoad];
self.personName = [[NSString alloc] initWithString:@"John Doe"];
NSLog(@"Name = %@", self.personName);
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
- (void)viewDidUnload
{
[super viewDidUnload];
}
- (void)dealloc
{
[super dealloc];
}
@end