Boon Boon - 10 months ago 264
Swift Question

Swift enum inheritance

Can you inherit enum in Swift? What are the rules that one should be aware of with regards to enum inheritance?

The following test code:

enum TemperatureUnit: Int {
case Kelvin, Celcius, Farenheit
}

enum TemperatureSubunit : Temperature {
}


generates

error: type 'TemperatureSubunit' does not conform to protocol 'RawRepresentable'

Answer Source

In swift language we have Structs,Enum and Classes.Struct and Enum are passed by copy but Classes are passed by reference.Only Classes support inheritance, Enum and Struct don't.So to answer your question you can't have inheritance with Enum (and Struct types). Have a look here

stackOverflow difference classes vs structs