Advertisement
Larme

Untitled

Oct 19th, 2020
1,053
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     NSArray *anArray = @[ @{@"identifier1": @{ @"3498239502323120": @{@"key1":@"abc",
  2.                                                                       @"key2": @123},
  3.                                                @"3493208429034821": @{ @"key1": @"def",
  4.                                                                        @"key2": @456}
  5.                                                
  6.                                             },
  7.                             @"identifier2": @{ @"456434234234": @{ @"key1": @"ghi",
  8.                                                                    @"key2": @789 },
  9.                                                @"8796554": @{ @"key1": @"jkl",
  10.                                                               @"key2": @101112 }
  11.                                                 }
  12.                             }];
  13.    
  14.     NSArray *identifier1 = [anArray valueForKeyPath:@"identifier1"];
  15.     NSLog(@"identifier1: %@", identifier1);
  16.     NSMutableArray *values = [[NSMutableArray alloc] init];
  17.     for (NSDictionary *aDict in identifier1)
  18.     {
  19.         NSArray *subdictionaries = [aDict allValues];
  20.         [values addObjectsFromArray:[subdictionaries valueForKey:@"key1"]];
  21.         for (NSDictionary *aSubdict in subdictionaries) {
  22. //                  OR
  23. //            NSString *aValue = aSubdict[@"key1"];
  24. //            if (aValue)
  25. //            {
  26. //                [values addObject:aValue];
  27. //            }
  28.         }
  29.     }
  30.    
  31.     NSLog(@"Values: %@", values);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement