Search code examples
objective-ccocoansarray

Flatten an NSArray


I have an array like this:

array: (
    (
        "http://aaa/product/8_1371121323.png",
        "http://aaa/product/14_1371123271.png"
    ),
    (
        "http://aaa/product/9_1371121377.png"
    )
)

and I have to create another array from that one like this

array: (
    "http://aaa/product/8_1371121323.png",
    "http://aaa/product/14_1371123271.png",
    "http://aaa/product/9_1371121377.png"
)

How can I do that? Is it possible to combine all the objects and separate them using some string?


Solution

  • Sample Code :

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