我不知道如何去做這件事。我有一個NSMutableArray(addList),其中包含要添加到我的數據源NSMutableArray的所有項目。NSMutableArray檢查對象是否已經存在
我現在想檢查從addList數組添加的對象是否已經存在於數據源數組中。如果不存在,則添加該項目,如果存在則忽略。
這兩個對象都有一個名爲iName的字符串變量,我想比較。
這裏是我的代碼片段
-(void)doneClicked{
for (Item *item in addList){
/*
Here i want to loop through the datasource array
*/
for(Item *existingItem in appDelegate.list){
if([existingItem.iName isEqualToString:item.iName]){
// Do not add
}
else{
[appDelegate insertItem:item];
}
}
}
,但我覺得,即使存在要添加的項目。
我在做什麼錯了?
這是一個邏輯錯誤,請參閱我的回答 – knuku 2011-06-09 11:04:02