I was trying to initialize an array containing optional values using the repeatedValues initializer and I was surprised to discover the following code doesn't compile
let a: Int?[] = Int?[](count: 10, repeatedValue:nil)
// error - Value of Int?[]? not unwrapped; did you mean to use '!' or '?'?
What's interesting is that type signature Int?[]?, e.g. an optional Array of optional Int. This feels like a bug but maybe there's something I'm missing about the grammar. I've looked through the language reference some but have yet to find an answer.
The more explicit Array<Int?> type initializer works as expected
let b: Int?[] = Array<Int?>(count: 10, repeatedValue:nil)
// compiles fine
Has anyone else run into this and can shed some light?
EDIT
Couple extra working examples with non-optional types to highlight the failure
let c: Int[] = Int[](count: 10, repeatedValue:0)
// non-optional shorthand works fine
class D { var foo = 1 }
let d: D[] = D[](count:10, repeatedValue:D())
// custom class works fine using the shorthand too
enum E { case a, b, c, d, e }
let e: E[] = E[](count:10, repeatedValue:.e)
// enums work too
let a = Int?[](count: 10, repeatedValue:nil), it compiles. However,ais described in the Playground view as{[nil, nil, nil, nil, nil, nil, nil, nil, nil, nil]}, not[nil, nil, nil, nil, nil, nil, nil, nil, nil, nil], which seems to imply that the actual type isn't what you're expecting with that particular initializer. I haven't learned enough about Swift yet to know what it all means, but thought I'd mention it anyway.let a: Array<Int?>? = Int?[](count:10, repeatedValue:nil)Int[]andInt?[]are two different types. The first is an array of integers (Array<Int>) while the second is an array of optional integers (Array<Int?>)