Vote count:
0
What is a slice in Swift and how does it differ from an array?
From the documentation, the type signature of subscript(Range) is:
subscript(Range<Int>) -> Slice<T>
Why not return another Array<T> rather than a Slice<T>?
It looks like I can concatenate a slice with an array:
var list = ["hello", "world"]
var slice: Array<String> = [] + list[0..list.count]
But this yields the error could not find an overload for 'subscript' that accepts the supplied arguments:
var list = ["hello", "world"]
var slice: Array<String> = list[0..list.count]
What is a slice?
asked 21 secs ago
Aucun commentaire:
Enregistrer un commentaire