views:

180

answers:

1

I've populated and array with data like this in one class...

PowerClass.h 

NSMutableArray pickerArray;
@property (nonatomic, retain) NSMutableArray pickerArray;

-

PowerClass.m

@synthesize pickerArray;

@implementation
NSMutableArray *array = [[NSArray alloc] initWithObjects:@"stef", @"steve", @"baddamans", @"jonny", nil];
pickerArray = [NSMutableArray arrayWithArray:array];

And I'm trying to set the Array in another class

WeekClass.h

PowerClass          *powerClass;
NSMutableArray  *pickerData;

@property (nonatomic, retain) NSMutableArray pickerData;
@property (nonatomic, retain) PowerClass *powerClass;

WeekClass.m

@implementation
pickerData = [NSMutableArray arrayWithArray:powerClass.pickerArray];

I have no errors or warnings. It just crashes. The NSLog says that the powerClass.pickerArray is NULL.

Please help point me in the right direction.

+1  A: 

Memory management!

You've set pickerArray = [NSMutableArray arrayWithArray:array];, which is an autoreleased object. By the time you ask for pickerArray later, it's disappeared!

The solution is to use the @synthesized accessors. Instead of:

pickerArray = [NSMutableArray arrayWithArray:array];

... use one of the following:

[self setPickerArray:[NSMutableArray arrayWithArray:array]];
self.pickerArray = [NSMutableArray arrayWithArray:array];
//These two are exactly equivalent, but are both very different from what you have now.

This way, your property will handle memory management for you.

andyvn22
Hi, Cheers I put my question wrong... Sorry... I meant Week Class picker.Data was null... What can I do?(Sorry, It was 4am UK when I sent it :-) )Thanx again...
Stef