Consider a struct nested inside another struct:
struct Struct1 {
struct Struct2 {
var name: String?
}
}
I want to create an array of Struct2
values. At first I tried:
var struct2Array = [Struct1.Struct2]()
But this gives the compiler error:
error: invalid use of '()' to call a value of non-function type '[Struct1.Struct2.Type]' var struct2Array = [Struct1.Struct2]()
I can create an array by declaring the type of the variable and using an empty array, or with the more verbose syntax:
var struct2Array: [Struct1.Struct2] = []
var struct2ArrayVerbose = Array<Struct1.Struct2>()
But why can't I use the shorthand initializer for a nested Struct?