Add field to enum in Swift

2020-04-05 06:48发布

I'm dealing with enum and subclassing in Swift. Each child bring its own new properties which have to be stored in an Enum. This enum is declared with some values in the mother class. I'd like to add some value to this enum. I can't find out how to do it, I tried this without result :

extension MotherClass {
    enum Enumeration {
        case NewProperty
    }
}

标签: ios enums swift
1条回答
家丑人穷心不美
2楼-- · 2020-04-05 07:40

The only way to add items to an enum is to add them directly to its declaration. You cannot add more items to an enum through inheritance or any other extension mechanism: the enum must be fully defined at the point of its declaration.

查看更多
登录 后发表回答