Array Count is 0 after adding an element?

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

Answers (3)

dom
dom

Reputation: 11972

Don't forget to initializing the NSMutableArray :)

platforms = [[NSMutableArray alloc] init];

Upvotes: 0

Andrey Zverev
Andrey Zverev

Reputation: 4428

Most likely you're not initializing your self.platforms array.

Upvotes: 0

Mark Leonard
Mark Leonard

Reputation: 2096

Probably you are forgetting to initialize the NSMutableArray itself. Check and make sure you're doing so.

Upvotes: 4

Related Questions