Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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] 

screenshot

like image 592
Liron Shapira Avatar asked Sep 07 '14 20:09

Liron Shapira


1 Answers

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) 
like image 64
Connor Avatar answered Oct 19 '22 09:10

Connor