How to concatenate two arrays into a single array in Objective-C?
NSArray* newArray = [firstArray arrayByAddingObjectsFromArray:secondArray];
Or using mutable array version just add to it all objects from another array:
[myMutableArray addObjectsFromArray:secondArray];
NSSArray *theArrayIReallyWant = [oneArrayIDontReallyWant arrayByAddingObjectsFromArray:otherArrayIDontReallyWant];
If you need to, retain theArrayIReallyWant
so it stays in memory, just be sure to release it when you are done.
That by far is the easiest method :)
With immutable arrays:
NSArray *arr1 = @[@(1), @(2), @(3)];
NSArray *arr2 = @[@(4), @(5), @(6)];
NSArray *arr3 = [arr1 arrayByAddingObjectsFromArray:arr2];
or adding onto a mutable array:
NSArray *arr1 = @[@(1), @(2), @(3)];
NSArray *arr2 = @[@(4), @(5), @(6)];
NSMutableArray *arr3 = [NSMutableArray arrayWithArray:arr1];
[arr3 addObjectsFromArray:arr2];