What is a slice in Swift?

后端 未结 3 1555
甜味超标
甜味超标 2020-12-13 01:16

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<         


        
3条回答
  •  孤城傲影
    2020-12-13 02:12

    The slice points into the array. No point making another array when the array already exists and the slice can just describe the desired part of it.

    The addition causes implicit coercion, so it works. To make your assignment work, you would need to coerce:

    var list = ["hello", "world"]
    var slice: Array = Array(list[0..

提交回复
热议问题