Boon Boon - 5 months ago 117
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 {


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


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