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. 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.

Sign up to request clarification or add additional context in comments.

3 Comments

Your title and text refer to an array of dictionaries :-)
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.
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];

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.