I am trying to declare an empty array of enum defined inside of another class as follows, and am getting the following error:
class OuterClass {
enum MyEnum {
case ThingOne
case ThingTwo
}
}
// Error: Invalid use of '()' to call a value of non-function type '[OuterClass.MyEnum.Type]'
var emptyEnumArray = [OuterClass.MyEnum]()
emptyEnumArray.append(.ThingOne)
However, I can declare the array as follows with no problem:
// No errors
var emptyEnumArray: [OuterClass.MyEnum] = []
This only appears to be an issue when the enum is defined inside of another class, as this works:
enum OtherEnum {
case ThingOne
case ThingTwo
}
var emptyArrayTwo = [OtherEnum]()
emptyArrayTwo.append(.ThingTwo)
Any thoughts on why the first snippet doesn't work? Is this a language bug?
I think it's a Swift bug right now. This also works.
var emptyEnumArray = Array<OuterClass.MyEnum>()
The question just recalls me to a question in apple Swift tutorial.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With