Enum in class in Swift

How do you access the enumeration of classes from outside the class?

  class Element
  {
    enum Type
    {
        case AUDIO
        case LIGHT
        case THERMOSTAT
    }
  }

  var a = Element.Type.LIGHT   // error: 'Element.Type.Type' does not have a member named 'LIGHT'

  var b = Element.LIGHT   // error: 'Element.Type' does not have a member named 'LIGHT'

      

+3


source to share


1 answer


A Type

property already exists (unlucky name :)), just rename it to something else, for example:



class Element
{
    enum EnumType
    {
        case AUDIO
        case LIGHT
        case THERMOSTAT
    }
}

var a = Element.EnumType.LIGHT

      

+6


source







All Articles