Initially, I was looking at the way "pickerData" is set and thinking I wonder why you can't just assign it directly (as in METHOD_002), but then I stated thinking that I should really be using the accessor methods I defined and not setting the instance variables directly. Am I understand this correctly that METHOD_001 is a better way of doing this?
@property(nonatomic, retain) IBOutlet NSArray *pickerData;
METHOD_001
-(void)viewDidLoad {
NSLog(@"VIEW: Single ... Loaded");
NSArray *dataArray = [[NSArray alloc] initWithObjects:@"A", @"B", @"C",nil];
[self setPickerData:dataArray];
[dataArray release];
[super viewDidLoad];
}
-(void)dealloc {
[pickerData release];
[super dealloc];
}
OR METHOD_002
-(void)viewDidLoad {
NSLog(@"VIEW: Single ... Loaded");
if(pickerData != nil) [pickerData release];
pickerData = [[[NSArray alloc] initWithObjects:@"A", @"B", @"C", nil] retain];
[super viewDidLoad];
}
-(void)dealloc {
[pickerData release];
[super dealloc];
}
EDIT_001:
First off I have added the "nil" values to terminate the NSArrays, coming from C I always forget this, my bad. Also you're right, I did not account for the fact in METHOD_002 that pickerData might already be set and as a result leak the old object. Once you start noticing these problems and fixing the code it starts to look like METHOD_001 is the best idea. Or to just use the property directly as Vladimir and eJames noted.
self.pickerData = [NSArray arrayWithObjects: @"A", @"B", @"C", nil];
EDIT_002:
Thank you for all the pointers and comments, for now I am going to stick with METHOD_001, I could just as easily use NSArrayWithObjects: but I am trying to keep memory usage low by releasing things myself as soon as I can (not that it matters here, but for future projects) Also I do like the feel of self.pickerData, but I am still unsure how I feel about dot-notation and have for now been trying to stick with old style objects and messages where possible. Again many thanks for the help.
gary