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];
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];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With