Want to concatenate or merge arrays in Swift? You can concatenate the arrays with +
, building a new array.
1 2 | let c = a + b print(c) // [1.0, 2.0, 3.0, 4.0, 5.0, 6.0] |
or append one array to the other with +=
:
1 2 3 4 5 6 7 8 | a += b // Or: a.append(contentsOf: b) // Swift 3 a.appendContentsOf(b) // Swift 2 a.extend(b) // Swift 1.2 print(a) // [1.0, 2.0, 3.0, 4.0, 5.0, 6.0] |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.