• Simple enumeration
enum CompassPoint { case north case south case east case west } var directionToHead = CompassPoint.north directionToHead  = .east enum Planet { case mercury,venus,earth,mars }Copy the code
  • Enumeration elements can be obtained by following the CaseIterable protocol
enum Beverage:CaseIterable { case coffee,tea,juice } Beverage.allCases.count for item in Beverage.allCases { print(item)  } /* coffee tea juice */Copy the code
enum CompassPoint:String {
    case north
    case south
    case east
    case west
}
CompassPoint.west.rawValue // "west"
Copy the code
enum Planet:Int {
    case mercury = 1,venus,earth,mars
}
Planet.earth.rawValue // 3
Copy the code