枚举 NSMutableDictionary 时难以根据键排除对象

发布于 2024-09-08 10:10:50 字数 661 浏览 0 评论 0原文

我很困惑。我有一个带有嵌套字典的 NSMutableDictionary,我正在枚举它以在嵌套字典中创建特定键值的数组,但我想排除两个“键”。

如果我排除一个键,我就可以做到这一点,但是一旦我尝试使用“||”或者我的 If 语句中的运算符它停止工作,只是将所有对象添加到我的新数组中,而不是所有对象,而是我试图过滤掉的两个对象。

我的枚举逻辑:

  for (NSString *key in self.myMutDictionary) {
   theBool = [key isEqualToString:@"First"];
   NSLog(@"Is key = to First? %@", (theBool ? @"YES" : @"NO"));

   if ((![key isEqualToString:@"First"]) || (![key isEqualToString:@"Second"])) {
    newDict = [self.myMutDictionary objectForKey:key];
    [self.filteredArray addObject:[newDict objectForKey:@"Third"]];
    NSLog(@"Filtered Array: %@", self.filteredArray);

   }}

感谢您的帮助!

I'm stumped. I have an NSMutableDictionary w/ nested dictionaries that I am enumerating through to create an Array of a particular key value in a nested dictionary, but I want to exlude two "keys".

I am able to do it if I exclude one key, but as soon as I try to use the "||" or operator in my If statement it stops working and just adds all the objects to my new array, instead of all objects, but the two I'm trying to filter out.

My enumerating logic:

  for (NSString *key in self.myMutDictionary) {
   theBool = [key isEqualToString:@"First"];
   NSLog(@"Is key = to First? %@", (theBool ? @"YES" : @"NO"));

   if ((![key isEqualToString:@"First"]) || (![key isEqualToString:@"Second"])) {
    newDict = [self.myMutDictionary objectForKey:key];
    [self.filteredArray addObject:[newDict objectForKey:@"Third"]];
    NSLog(@"Filtered Array: %@", self.filteredArray);

   }}

Thanks for your help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

帝王念 2024-09-15 10:10:50

改变||到&&

如果它不是第一个也不是第二个,则将其包括在内。

您想要排除 (A OR B),但您要反转整个表达式来选择要包含的内容,因此应该是 (!A AND !B)

Change || to &&

If it's not First AND not Second then include it.

You want to exclude (A OR B), but you're inverting the whole expression to select what to include, so it should be (!A AND !B)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文