Possible Duplicate:
NSMutableArray addObject not working
I have a NSMutableArray declared as (nonatomic,retain) in my .h file, and properly synthesized. tempRandomWord is an NSString that is always populated.However,count is always returning 0. Any ideas why?
[pastWords addObject:tempRandomWord];
int count=[pastWords count];
NSLog(@"%i",count);
Your array is not initialized.
just add a lazy initialization somewhere before you read/use the property.
or if you use iVars directly:
or normal initialization in init
If you assign that property from outside of the class you may want to call mutableCopy to make sure the mutable array is used, even if NSArray is assigned.