Flatten an NSArray

It can be done in a single line if you like key-value coding (KVC). The @unionOfArrays collection operator does exactly what you are looking for.

You may have encountered KVC before in predicates, bindings and similar places, but it can also be called in normal Objective-C code like this:

NSArray *flatArray = [array valueForKeyPath: @"@unionOfArrays.self"];

There are other collection operators in KVC, all prefixed with an @ sign, as discussed here.


Sample Code :

NSMutableArray *mainArray = [[NSMutableArray alloc] init];
for (int i = 0; i < bigArray.count ; i++)
{
     [mainArray addObjectsFromArray:[bigArray objectAtIndex:i]];
}
NSLog(@"mainArray :: %@",mainArray);

Sample code:

NSArray* arrays = @(@(@"http://aaa/product/8_1371121323.png",@"http://aaa/product/14_1371123271.png"),@(@"http://aaa/product/9_1371121377.png"));
NSMutableArray* flatArray = [NSMutableArray array];
for (NSArray* innerArray in arrays) {
    [flatArray addObjectsFromArray:innerArray];
}

NSLog(@"%@",[flatArray componentsJoinedByString:@","]);