sub-array

In Swift, Array [String] slicing return type doesn't seem to be [String]

穿精又带淫゛_ 提交于 2019-11-26 05:32:00
问题 I\'m slicing an array of strings and setting that to a [String] variable, but the type checker is complaining. Is it a possible compiler bug? var tags = [\"this\", \"is\", \"cool\"] tags[1..<3] var someTags: [String] = tags[1..<3] 回答1: Subscripting an array with a range doesn't return an array, but a slice. You can create an array out of that slice though. var tags = ["this", "is", "cool"] tags[1..<3] var someTags: Slice<String> = tags[1..<3] var someTagsArray: [String] = Array(someTags) 回答2: