Search code examples
iosobjective-cnsmutablearraynsdecimalnumber

NSMutableArray not adding NSDecimalNumber


I'm trying to add NSDecimalNumbers to an NSMutableArray. Here is the code:

for (int i = 0; i < [dollarArray count]; i++)
{
    NSString *string = [NSString stringWithFormat:@"%@.%@", [[firstArray objectAtIndex:i] firstObject], [[secondArray objectAtIndex:i] firstObject]];
    NSDecimalNumber *number = [NSDecimalNumber decimalNumberWithString:string];
    [arrData addObject:number];
}
NSLog(@"%@ and %@", number, arrData);

The results for number is correct - it shows all the numbers. But for arrData, it shows null. Is it not correct the way I add decimalNumber to arrData? What should I do to fix this?


Solution

  • Did you initialise arrData properly? NSMutableArray *arrData = [NSMutableArray new];