It doesn’t work because this:
doesn’t create an array.
I assumed the first block of code would work because the following code DOES work:
But those two lines aren’t similar at all, so I’m not sure why the latter would lead you to think the former would work. In the latter line, you are creating an array from a range of Int
s; in the first line, you are trying to print the value of an array. Two completely different things.
These lines:
var thisOtherArray: [String] = [" "]
var arrayOfValues = Array(10…19)
do create arrays. (Though note that neither one is an empty array, as they both are created containing values.)
To create an empty String
array, you need to use one of these approaches:
var thisOtherArray: [String] = []
var thisOtherArray = Array<String>()