Skip to content

Instantly share code, notes, and snippets.

@epatel
Created April 29, 2011 20:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save epatel/948970 to your computer and use it in GitHub Desktop.
Save epatel/948970 to your computer and use it in GitHub Desktop.
flattenArray(array) -- flattens a hierarchy of NSArrays (should be a category I guess) [reason https://twitter.com/ikenndac/status/63609670182502400 -- but not a oneliner]
NSArray *flattenArray(NSArray *arr) {
NSMutableArray *collector = [NSMutableArray array];
for (id obj in arr) {
if ([obj isKindOfClass:[NSArray class]])
[collector addObjectsFromArray:flattenArray(obj)];
else
[collector addObject:obj];
}
return collector;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment