7

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?

1
  • looked at it myself, and seems a lot like a bug yes. Have you tried running it with compiler warnings turned off? Commented Sep 29, 2015 at 2:24

1 Answer 1

6

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.