0

Background:

a Object:

MyObject : NSObject
@property NSInteger type;

a NSDictionary:

@{
@"1":@{@"1":MyObject}
@"2":@{@"1":MyObject}
}

Now,got a MyObject and it's type=1; how to make sure whether this MyObject contained in the NSDictionary?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Dwight
  • 23
  • 1
  • 5

1 Answers1

0

I'm taking into consideration, that your dictionary only has one key/pair and there are no similar key names present

  NSDictionary *dict = @{ @"a":@{@"c":@"MyObject"}                                        ,@"b":@{@"d":@"MyObject"} } ;

NSMutableArray *valuesArray = [[NSMutableArray alloc]init];
 // enumerate and add all values to our value array
[dict enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
    NSLog(@"Your value : %@", [obj description]);

    [valuesArray addObject:[[obj allValues] firstObject]];
}];

// check whether this value is present
if ([valuesArray containsObject:@"MyObject"]) {
    NSLog(@"My Object found",);
}
Misha
  • 685
  • 8
  • 20