The others’ answers are correct. If you want to know the reasoning for it, or why : [Int]
fixes it, see here:
(That post is about Data
, but it applies to Array
too.)
let combo2 = array1[2...] + array2
The fact that this even compiles seems like an unfortunate accident to me. It is very unclear what type it is supposed to produce. I’ve been working with Swift for years and even I had to run it through the compiler to find out that it results in an ArraySlice
. (I expected some sort of FlattenSequence
.) But this seems to be a butchering of what a slice is supposed to be. A slice of what? Printing it demonstrates that all the right elements are there. But the indices correspond neither to 0‐based logic, nor to the indices of any of its components. And slices hold onto the entire memory of their base collection. What memory is that abomination holding onto behind the scenes? Or allocating?
Even though +
is available (presumably it was necessary for protocol conformance), I don’t recommend ever using it on an ArraySlice
. Do something like the following instead, so that you always know very clearly what is happening with indices and memory under the hood:
let combo2 = Array(array1[2...]) + array2