1

I have an array or dictionaries. The dictionaries and keys are like this:

[@"Ford", @"brand",  
 @"Fiesta", @"model",  
 @"1980", @"year"]

[@"Chevrolet", @"brand",  
 @"Corvette", @"model",  
 @"2000", @"year"]

[@"Chrysler", @"brand",  
 @"S Model", @"model",  
 @"2013", @"year"]

I would like to extract the data from this array of dictionaries and transform this into arrays like this:

arrayOfBrands: [@"Ford", @"Chevrolet", @"Chrysler"];
arrayOfModels: [@"Fiesta", @"Corvette", @"S Model"];
arrayOfYears: [@"1980", @"2000", @"2013"];

Yes I know I can iterate over the array of dictionaries and create a complex code to do that. But on the other hand I know that Objective-C is a bag of tricks and there is probably a built in way to do that faster and cleaner. Isn't it? Thanks

Duck
  • 34,902
  • 47
  • 248
  • 470

1 Answers1

3

try like this,

NSArray *array= [arr valueForKeyPath:@"brand"];
Balu
  • 8,470
  • 2
  • 24
  • 41