From Swift Programming Guide:
You can create an empty array of a certain type using initializer syntax:
var someInts = [Int]() println("someInts is of type [Int] with \(someInts.count) items.") // prints "someInts is of type [Int] with 0 items."Note that the type of the
someIntsvariable is inferred to be[Int]from the type of the initializer.
But if you actually copy this as is into XCode, and check the type of someInts, you get [(Int)], which is an array of single element Int tuples. Why this discrepancy? You can also initialize an array as follows:
var someInts: [Int] = []
That has the correct type.
Practically these types seem to behave the same, but I'm trying to figure out what's going on here.
Also in the reference doc for Array it says:
Creating an array using this initializer:
var emptyArray = Array<Int>()is equivalent to using the convenience syntax:
var equivalentEmptyArray = [Int]()
But emptyArray above has the type Array<Int> while equivalentEmptyArray has type [(Int)] as in the previous example. Array<Int> is just the full form of [Int] though, so this isn't really a problem, except that the latter doesn't match the type the doc says it is.
Note: finding types by option-clicking on the variable or by selecting it and looking in the Quick Help Inspector in the right side menu.