I am 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
You mixed up the alloc
/init
calls. alloc
comes first. It should be:
NSMutableArray *current_classes = [[NSMutableArray alloc] init];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With