このループで何が問題なのかよく分かりませんが、実行するたびにSIGABRTを取得し続けます。ログによると、ループの終わり近くでNSMutable配列にNSNumberを追加しようとすると問題が発生します。明らかに私は基本的なエラーを作りましたが、私はその問題が何であるか分かりません。問題ループ内のNSMutableArrayに追加する
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;
ここにログ履歴を追加できますか? – Sarah
詳細なコード、特に 'allValuesMArray'の作成を表示してください。また、 '[product release]'を削除すると、後でクラッシュする可能性があります。最後に、BOOL型の適切な定数は、 'TRUE' /' FALSE'ではなく、 'YES' /' NO'です。 –
まだ十分ではない場合、何が起こっているのかをもっと表示するためにコードを編集しました他に何が必要なのか教えてください。ループの上のすべてがうまくいくはずですが、私が望むものを得るための最良の方法は正確ではありません。このメソッドのポイントは、toArrayから数値のリストを読み込み、製品を計算し、各製品を新しい配列に格納し、返されてpリストに書き込まれることです。 – Justin