在我的应用程序中,我收到了来自服务器的响应,我必须检查我没有在NSArray
其中创建重复的对象NSDictionaries
。现在要检查对象是否存在,我这样做:
for (int i = 0; i < appDelegate.currentUser.userSiteDetailsArray.count; i++){
NSDictionary *tmpDictionary = [appDelegate.currentUser.userSiteDetailsArray objectAtIndex:i];
if ([[tmpDictionary valueForKey:@"webpropID"] isEqualToString:tmpWebproperty.identifier]){
needToCheck = NO;
}
if (i == appDelegate.currentUser.userSiteDetailsArray.count - 1 && ![[tmpDictionary valueForKey:@"webpropID"] isEqualToString:tmpWebproperty.identifier] && needToCheck){
// It means it's the last object we've iterated through and needToCheck is still = YES;
//Doing stuff here
}
}
我设置了一个BOOL
值,因为这个迭代在一个方法中进行了很多次,我不能用return
它来停止它。我认为有更好的方法来执行此检查,我想听听您对此的建议。