本文介绍了NSMutableArray中NSDictionary存储中的搜索字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在NSMutableArray

for (int k = 0; k < [onlyActiveArr count]; k++) {

    NSString *localID = [onlyActiveArr objectAtIndex:k];
    NSLog(@"%@",localID);

    int localIndex = [onlyActiveArr indexOfObject:localActiveCallID];
    NSLog(@"%d",localIndex);

    for (NSDictionary *dict in self.SummaryArr) {

        NSLog(@"%@",[dict objectForKey:@"ActiveID"]);

             if (![[dict objectForKey:@"ActiveID"] isEqualToString:localID]) {
                   NSLog(@"found such a key, e.g. %@",localID);

             }

    }
}

但是我得到

NSLog(@"found such a key, e.g. %@",localActiveCallID);

SummaryArr中的ID仍然存在时,我正在检查从onlyActiveArr中检索到的localID是否在词典中不存在.

when the ID is still there in SummaryArr, I am checking if localID retrieved from onlyActiveArr is not present in dictionary.

请建议我如何克服我的问题.

Please suggest me how to overcome my problem.

推荐答案

在完成整个字典的处理之前,您无法确定不存在密钥.创建一个布尔变量,最初将其设置为NO,如果在字典中找到一个项目,则将其更改为YES,如下所示:

You cannot make a decision that a key is not present until you finish processing the entire dictionary. Make a boolean variable initially set to NO, and change it to YES if you find an item in the dictionary, like this:

BOOL found = NO;
for (NSDictionary *dict in self.SummaryArr) {
     NSLog(@"%@",[dict objectForKey:@"ActiveID"]);
     found = [[dict objectForKey:@"ActiveID"] isEqualToString:localID];
     if (found) break;
}
if (!found) {
    NSLog(@"found such a key, e.g. %@",localID);
}

这篇关于NSMutableArray中NSDictionary存储中的搜索字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 14:58