views:

271

answers:

1

Hey guys. I'm getting a weird error, and I can't figure it out. This takes place inside of a class that is created with the singleton pattern:

- (NSMutableArray *) getCurrentClasses
{
    NSMutableArray *current_classes = [[NSMutableArray init] alloc];
    NSLog([NSString stringWithFormat:@"%d", [current_classes count]]);
    ...
}

When I run this, even though I literally just initialized current_classes, it gives me this error in log:

* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[NSCFArray count]: method sent to an uninitialized mutable array object'

Does anyone know what this is happening? I initialized it literally last line.

Thanks

+9  A: 

You mixed up the alloc/init calls. alloc comes first. It should be:

NSMutableArray *current_classes = [[NSMutableArray alloc] init];
mipadi
*epic facepalm* Thank you.
Ethan