0

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 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.