views:

27

answers:

1

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!

+2  A: 

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)

progrmr
Wow. I think I've been trying too hard today! Of course, this fixed the problem. Thanks for the explanation as well!
Zigrivers