Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add field to enum in Swift

Tags:

enums

ios

swift

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
    }
}
like image 284
Aeradriel Avatar asked Aug 11 '14 11:08

Aeradriel


1 Answers

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.

like image 154
Sergey Kalinichenko Avatar answered Oct 09 '22 11:10

Sergey Kalinichenko