【发布时间】:2011-09-11 14:16:49
【问题描述】:
我不知道该怎么做。我有一个 NSMutableArray (addList),其中包含要添加到我的数据源 NSMutableArray 的所有项目。
我现在想检查要从 addList 数组添加的对象是否已存在于数据源数组中。如果不存在则添加该项目,如果存在则忽略。
这两个对象都有一个我想比较的名为 iName 的字符串变量。
这是我的代码 sn-p
-(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];
}
}
}
但我发现要添加的项目即使存在。
我做错了什么?
【问题讨论】:
-
逻辑错误,看我的回答
标签: iphone objective-c ios nsmutablearray