Merging NSArrays in Objective-C

Coocoo4Cocoa picture Coocoo4Cocoa · Aug 14, 2009 · Viewed 19.1k times · Source

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];
NSMutableArray *newArray = [NSMutableArray array];
start outter loop on anArray
   start inner loop on objects in anArray
     add objectAtIndex to newArray

Answer

Ben Gottlieb picture Ben Gottlieb · Aug 14, 2009

Just use [newArray addObjectsFromArray:anArray];