-5

How to get contents of NSMutableDictionary into NSMutable array?

I am trying following but its crashing

for(int i=0; i< [dict count] ; i++){

  [array_listToDisplay addObject:[dict objectAtIndex:i] objectForKey:@"NAMES"];
}

Please help

Mudassir
  • 13,031
  • 8
  • 59
  • 87
iOSDev
  • 3,617
  • 10
  • 51
  • 91
  • dictionary consist of objects and keys which are array if you successfully try to gets keys and objects may be you will be able to map NSMutableDictionary into NsMutableArray – Leena Dec 12 '11 at 05:34
  • http://stackoverflow.com/questions/2274022/nsdictionary-to-nsarray – Parag Bafna Dec 12 '11 at 05:34
  • Did you look at the console to find out *why* it's crashing? I'll bet you get a message there that says `dict` does not respond to the selector `-objectAtIndex:`. Dictionaries are not arrays, and NSDictionary doesn't provide a `-objectAtIndex:` method. – Caleb Dec 12 '11 at 05:35
  • I don't understand what you are trying to do. The code you've got is completely wrong. I see you've got a `dict` variable and an `array_listToDisplay` variable. Which objects in `dict` do you want to add to the array? – Abhi Beckert Dec 12 '11 at 06:00

2 Answers2

9

Do you want the dictionary's keys, or the dictionary's values?

NSMutableArray *keys = [NSMutableArray arrayWithArray:[dict allKeys]];
NSMutableArray *values = [NSMutableArray arrayWithArray:[dict allValues]];
rob mayoff
  • 375,296
  • 67
  • 796
  • 848
1

If you're trying to add all the objects in the dictionary to the array, you just do this:

[array_listToDisplay addObjectsFromArray:[dict allValues]];
Abhi Beckert
  • 32,787
  • 12
  • 83
  • 110