NSMutableArray
Personタイプのオブジェクトを含むがあります。Personオブジェクトには、NSString
* name、NSString
* dateStamp、およびNSString
*testScoreのパラメーターが含まれています。高速列挙を使用して実行したいのは、NSMutableArray
* testResultsで確認し、同じ名前のパラメーターを持つオブジェクトが存在するかどうかを確認することです。
含まれている場合は、の既存のオブジェクトを、NSMutableArray
挿入しようとしているオブジェクトに置き換えます。このオブジェクトには、最新のdateStamp
testScore値が含まれます。名前パラメータが一致しないオブジェクトが見つかった場合は、私が持っているオブジェクトを挿入するだけです。
これまでの私のコードは次のようになります。
これは、挿入しようとしているオブジェクトを作成するコードです。
Person *newPerson = [[Person alloc] init];
[newPerson setPersonName:newName]; //variables newName, pass, and newDate have already been
[newPerson setScore:pass]; //created and initialized
[newPerson setDateStamp:newDate];
これは、NSMutableArrayを反復処理して、同じ名前のパラメーターを持つオブジェクトが既に存在するかどうかを確認するコードです。
for (Person *checkPerson in personList) { //personList is of type NSMutableArray
if (newPerson.newName == checkPerson.name) {
//here is where I need to insert the code that replaces checkPerson with newPerson after a match has been found
}
else {
personList.addObject(newPerson); //this is the code that adds the new object to the NSMutableArray when no match was found.
}
}
それほど複雑な問題ではありませんが、一致するものを見つけて、オブジェクトがどのインデックスにあるかを事前に知らずに実際のオブジェクトを置き換える方法について混乱しています。