0

I'm learning iOS but have an issue extracting data from a multidimensional NSMutableArray, I've looked at various solutions but have not yet found one..

I have an NSMutableArray like

{
 "service_0" = {
    "name" = "name1";
    "description" = "description1";
};
 "service_2" = {
    "name" = "name2";
    "description" = "description2";
};
Etc...
}

I wish to extract data into a new NSMutableArray (or NSArray) to get the following output for use in text labels such as = [myArray objectAtIndex:indexPath.row]

(
    name1,
    name2,
Etc...
)

What would be the best solution? Thanks

1
  • This looks more like a dictionary of dictionaries.
    – zaph
    Commented Sep 23, 2012 at 21:18

1 Answer 1

1

Assuming that is an array of dictionaries, unlike in the question...

NSArray *newArray = [oldArray valueForKeypath:@"name"];

You can make it mutable using mutableCopy, if you wish.

3
  • Your title and text refer to an array of dictionaries :-)
    – Paul Lynch
    Commented Sep 23, 2012 at 21:09
  • Handling a dictionary of dictionaries is far more problematic, and needs a few more lines of code (as in your answer). [[dictionary allValues] valueForKeypath:@"name"] would work, however.
    – Paul Lynch
    Commented Sep 23, 2012 at 21:14
  • Thanks guys, for the quick responses! .. I changed the array to a dictionary as suggested and extracted the rows using .. [[[myArray allValues] valueForKeyPath:@"name"] objectAtIndex:indexPath.row];
    – Peej
    Commented Sep 23, 2012 at 23:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.