NSMutableArray insertion in objective-C
I am using the following code to add NSNumber to a NSMutableArray
in header file:
NSNumber *timeInSeconds;
NSMutableArray *time;
in code:
int total=6;
timeInSeconds=[NSNumber numberWithInt:total]开发者_运维技巧;
[time addObject:timeInSeconds];
However, while debugging, I noticed that if I do
print (int) [time count]
I get an output of 0 ... Not sure why this is happening...can anyone kindly help me ?
Thanks.
I don't see where you allocated time
. At some point you need to call
time = [[NSMutableArray alloc] init];
or some other allocation and initialization method.
精彩评论