开发者

Difficult exluding objects based on key while enumerating an NSMutableDictionary

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 al开发者_StackOverflow中文版l 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!


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)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜