views:

488

answers:

2

I have an NSDictionary where each key points to an array. I later want to merge all of the values into one array. Is there a way to use the API to do something more efficient than say:

NSArray *anArray = [someDictionary allValues];
NSArray *newArray = [NSMutableArray array];
start outter loop on anArray
   start inner loop on objects in anArray
     add objectAtIndex to newArray
+5  A: 

-[NSMutableArray addObjectsFromArray:]

Chuck
+6  A: 

just use [newArray addObjectsFromArray: anArray]

Ben Gottlieb
Hi Ben, If I do it this way I don't have a flat array. I have an array of arrays. I was seeing if it was possible to do it without the looping.
Coocoo4Cocoa
This should still give you a flat array; you're not adding the array, you're adding the objects FROM the array.
Ben Gottlieb
Coocoo4Cocoa: I think you've confused `addObject`**`FromArray:`** with `addObject:`. `addObject:` adds *the array* to the new array, whereas what Chuck and Ben Gottlieb have suggested adds the elements in the array to the new array.
Peter Hosey