I have an array of strings in Swift that I want to shorten to only the first 5. It looks like I cannot do:
myArray = myArray[0..<5]
because I get a compiler error:
Cannot subscript a value of type [String] with an index of type Countable Range
So what can I do instead?
myArray[0..<5]is legal so you don't have what you think you have; this is probably an x-y problem, and we could get to the heart of it if you showed the real code.myArray[0..<5]may be legal,array.prefix(n)is a safer way since it is bounds safe!