Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't add to NSMutableArray

This is getting silly and driving me crackers.

I have a small test view controller where I loop through ten questions. The answer get checked and the score goes up or stays the same. This happens in a -(void) checkAnswer. No problem!

Now comes my headache. I have a NSMutableArray declared and @property in .h It's @synthesize in .m

But when I try to add "right' or "wrong" to it in checkAnswer, nothing get added.

 [scoreArray addObject:@"wrong"];
 NSLog(@"scoreArray checkAnswer: %@",scoreArray);

There is no warnings or errors, just getting (null) from the NSLog.

Tried with no joy.

  [self.scoreArray addObject:@"wrong"];

Anyone out there that could help me? I'm sure it's something simple I can't see. Thanks

like image 407
Jorgen Avatar asked Jul 14 '26 19:07

Jorgen


1 Answers

Have you initialized array correctly?

scoreArray = [[NSMutableArray alloc] init];
like image 108
Bartek Avatar answered Jul 20 '26 05:07

Bartek



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!