So I wanted to insert the objects of an array into another array. Swift arrays seem to missing an equivalent method to - (void)insertObjects:(NSArray *)objects atIndexes:(NSIndexSet *)indexes, but all is well because we can use the following syntax:
var array = [0,4,5]
array[1..<1] = [1,2,3] // array = [0,1,2,3,4,5]
All is well? Not quite! The following gives a compile-time error ("[Int] is not convertible to Int"):
var array = [0,4,5]
var array2 = [1,2,3]
array[1..<1] = array2
Is there a sane explanation for this?
Edit:
Ok, the following works (thanks Greg):
array[1..<1] = array2[0..<array2.count]
As well as this:
let slice = array2[0..<array2.count]
array[1..<1] = slice
But right now I'm utterly confused how this works. Gregs explanation that I was trying to insert array2 itself into array makes sense, but I fail to see the difference to just using an array literal, as well as why it works with a slice (which seems to be an undocumented implementation detail?).
array[1..<1] = [1,2,3]works. But there is no automatic conversion from Array to Slice or vice versa.