我不确定这个循环到底有什么问题,但是每当我运行它时,我都会不断收到 SIGABRT。根据日志,问题是当我尝试将 NSNumber 添加到循环结束附近的 NSMutable 数组时。显然我犯了一个基本错误,但我不确定问题是什么。
NSArray *toArray = [ourDictionary objectForKey:toString];
NSMutableArray *allValuesMArray = [[NSMutableArray alloc] init];
while (done == NO)
{
if (i == 10)
done = YES;
/*
*The job here is to multiply these three numbers together and store the
*product in the mutable array. It tells me NSObject did not recognize selector
*and then crashes.
*original and multiplyFrom are always the same value, and multiplyTo is updated
*from an array I made above from a p-list.
*I'm hoping I didn't make a ton of rookie mistakes here, but I'm new to dealing with
*NSMutableArray and such.
*/
NSNumber *original = [NSNumber numberWithDouble:convertThis];
NSNumber *multiplyFrom = [NSNumber numberWithDouble:multiply];
NSNumber *multiplyTo = [NSNumber numberWithDouble:[[toArray objectAtIndex:i] doubleValue]];
NSNumber *product = [[NSNumber alloc] init];
product = [NSNumber numberWithDouble:([original doubleValue] *
[multiplyFrom doubleValue] *
[multiplyTo doubleValue])];
[allValuesMArray addObject:product];
//This line ^^^ causes crash
i++;
}
NSArray *returnThisArray = allValuesMArray;
[allValuesMArray autorelease];
return returnThisArray;