Reputation: 43
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;
Upvotes: 0
Views: 96
Reputation: 11972
Don't forget to initializing the NSMutableArray :)
platforms = [[NSMutableArray alloc] init];
Upvotes: 0
Reputation: 4428
Most likely you're not initializing your self.platforms
array.
Upvotes: 0
Reputation: 2096
Probably you are forgetting to initialize the NSMutableArray itself. Check and make sure you're doing so.
Upvotes: 4