Boon Boon - 1 year ago 368
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'

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download