オブジェクトの特定の値 (つまり ) に従って並べ替えたいオブジェクトの配列がありますself.example.value
。複数の可変配列を作成しました。
NSMutableArray *array1, *array2, *array3 = [[NSMutableArray alloc] initWithObjects: nil];
次に、for ループを使用して元の配列を反復処理します。オブジェクトが条件に一致した場合 ( self.example.value == someValue
)。上で作成した新しい配列の 1 つにオブジェクトを追加します。しかし、後で配列を使い始めると、配列が空であることに気付きました。デバッガーを使用して、次のことに気付きました。
for (customClass *object in arrayOfObject){ //starting here the debugger has NONE of the arrays created above
if (object.value == someValue){//after performing this line, the debugger shows array1 in memory BUT nothing in it EVEN if the 'if' statement isn't TRUE.
[array1 addobject:object];
} else if (object.value == someOtherValue){//after performing this line, the debugger shows array2 in memory BUT nothing in it EVEN if the 'if' statement isn't TRUE.
[array2 addobject:object];
} //and so forth
したがって、基本的に、for ループを繰り返すたびに、上で作成した配列がクリアされます。コードが進むにつれて、「if」ステートメントが TRUE であるかどうかに関係なく、配列は割り当てられますが、値は設定されません。ここで何が欠けていますか?