0
struct SomeStruct {
    struct AnotherStruct {
        var int: Int
    }

    var int: Int
}


var someArray = [SomeStruct.AnotherStruct]()  // error
var anotherArray = Array<SomeStruct.AnotherStruct>()  // this works

For the code above, I get a cannot call value of non-function type '[SomeStruct.AnotherStruct.Type]'. Is this a bug or something that we're stuck with, so we have to use the Array notation?

funct7
  • 3,407
  • 2
  • 27
  • 33

1 Answers1

0

This is a bug and raise at bugs.swift.org SR349 . you also can't declare empty array of nested class using this.

var someArray = [SomeClass.AnotherClass]()  // error

You can use this syntax to declare empty array of struct inside struct like this

 var someArray: [SomeStruct.AnotherStruct] = []
Sahil
  • 9,096
  • 3
  • 25
  • 29
  • True, but `[Type]()` is my favorite notation... I can only think this is a bug. – funct7 Mar 21 '17 at 04:44
  • yes! this is a bug. i'm also not able to create epmty array of class inside class using this syntax. – Sahil Mar 21 '17 at 05:33