[Solved] Swift 4: Array index out of Range


You declared an array of String

var stringArray = [String]()

Then you appended one element

stringArray.append(forss as! String)

That means only index 0 is valid

stringArray[0]

and you get an out-of-range error for

stringArray[1]
stringArray[2]
etc.

Note:

The question is not particularly related to Swift 4. All versions of Swift exhibit this behavior.

0

solved Swift 4: Array index out of Range