You can do this with @unionOfArrays
. The bit you were missing is that because the arrays are directly nested, the key on the right of the collection operator must be self
:
NSArray *nestedValues = @[@[@1, @2, @3], @[@4, @5, @6]]
NSArray *flattenedValues = [nestedValues valueForKeyPath:@"@unionOfArrays.self"];
// flattenedValues contains @[@1, @2, @3, @4, @5, @6]
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…