Concatenation of two arrays in Objective-C

前端 未结 3 1471
我在风中等你
我在风中等你 2021-02-06 21:42

How to concatenate two arrays into a single array in Objective-C?

3条回答
  •  别那么骄傲
    2021-02-06 22:15

    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];
    

提交回复
热议问题