Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Objective C: NSMutableArray does not retain objects

I'm so stumped by this, I set the object in the array, but when I check it after they're all set, it comes up as (null)

for (int i = 0; i < [lines count]; i+=2) {
    [terms addObject:[lines objectAtIndex:i]];
    NSLog(@"%@",[terms objectAtIndex:i]);
}

Am I doing something wrong? terms is declared in the header, set as a property, and synthesized as an NSMutableArray

like image 982
Chris Avatar asked Jul 16 '26 10:07

Chris


1 Answers

You have to first alloc and init the array before you use it. Setting the property makes it accessible outside the class and the synthesizer sets up the getter and setter but it doesn't alloc and init it.

NSMutableArray* terms = [[NSMutableArray alloc] init];
like image 182
Steve Moser Avatar answered Jul 18 '26 00:07

Steve Moser