NSMutable Array won't alloc, remains nil

130 Views Asked by At

A XML parser is trying to alloc its delegate's NSMutable array called masterCodeList. From the following code, you'll see that this fails. (I am a total newbie.)

if (dataController.masterCodeList == nil){

    dataController.masterCodeList =[[NSMutableArray alloc] init];
    if (dataController.masterCodeList == nil) {
        NSLog(@"the init of the mutable array did NOT work");
    }
}

I get the the init of the mutable array did NOT work message every time. I am importing the dataController header.

#import "CodeDataController.h"

I am getting no other error message, the parser is parsing fine and the app is running smoothly without content.

Thanks in advance.

2

There are 2 best solutions below

1
On

What does your declaration of masterCodeList look like? Is it a property, and is it synthesized, or are you making your own setter/getter?

An alternative would be to try using an intermediate placeholder, ie:

NSMutableArray *temp = [[NSMutableArray alloc] init];
[dataController setMasterCodeList:temp];

and see if that sets your array correctly.

(note: that code may or may not have leaks)

1
On

could you post your implementation of the dataController object in this class, and its attributes from the other class?

you also may want to try using the isEqual method instead of == nil.