views:

513

answers:

1

Did I say "array" enough for you there? To clarify:

I'm working on organizing and array in an iPhone project. I have an array of arrays. Each sub array has a list of items. How can I make a new array of all the items contained in the sub arrays?

I've experimented with the addObjectsFromArray function with little luck. Thanks!

+2  A: 
NSMutableArray * allSubItems = [NSMutableArray array];
for (NSArray * subArray in mainArray) {
  [allSubItems addObjectsFromArray:subArray];
}

If you want to eliminate duplicates, use an NSMutableSet instead of an NSMutableArray.

Dave DeLong