I know, enumeration constant should be like this in swift
enum CompassPoint { case North case South case East case West }
But how can I assign value to first element, like Objective-C code as below
enum ShareButtonID : NSInteger { ShareButtonIDFB = 100, ShareButtonIDTwitter, ShareButtonIDGoogleplus }ShareButtonID;
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 // => 100 let rawSouth = CompassPoint.South.rawValue // => 101 // etc.
Update: Replace toRaw()
with rawValue
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With