0

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;

3 Answers 3

4

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

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

0

Don't forget to initializing the NSMutableArray :)

platforms = [[NSMutableArray alloc] init];

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.