I’m using the code below to add an Object of my Platform class (basic storage class, subclass of NSObject) to an NSMutableArray.
But the NSLog statement outputs 0.
How can this happen?
Platform *platform = [Platform platformWithLabel:label identifier:identfier];
[self.platforms addObject:platform];
NSLog(@"%i", [self.platforms count]);
This is the creation method of Platform:
+(Platform *)platformWithLabel:(NSString *)label identifier:(int)identifier
{
Platform *platform = [[Platform alloc] init];
platform.label = label;
platform.identifier = identifier;
return platform;
}
I’m using ARC. This is how I declare my platforms array:
@property (strong, nonatomic) NSMutableArray *platforms;
Probably you are forgetting to initialize the NSMutableArray itself. Check and make sure you’re doing so.