swift : Enum constant with type and value
You need to give the enum a type and then set values, in the example below North
is set as 100
, the rest will be 101
, 102
etc, just like in C
and Objective-C
.
enum CompassPoint: Int { case North = 100, South, East, West}let rawNorth = CompassPoint.North.rawValue // => 100let rawSouth = CompassPoint.South.rawValue // => 101// etc.
Update: Replace toRaw()
with rawValue
.