Ios swift:具有类型和值的枚举常量

Ios swift:具有类型和值的枚举常量,ios,objective-c,enums,swift,ios8,Ios,Objective C,Enums,Swift,Ios8,我知道,枚举常数在swift中应该是这样的 enum CompassPoint { case North case South case East case West } 但我如何为第一个元素赋值,比如下面的Objective-C代码 enum ShareButtonID : NSInteger { ShareButtonIDFB = 100, ShareButtonIDTwitter, ShareButtonIDGoogleplus }Sh

我知道,枚举常数在swift中应该是这样的

enum CompassPoint {
    case North
    case South
    case East
    case West
}
但我如何为第一个元素赋值,比如下面的Objective-C代码

enum ShareButtonID : NSInteger
{
   ShareButtonIDFB = 100,
   ShareButtonIDTwitter,
   ShareButtonIDGoogleplus

}ShareButtonID;

您需要给枚举一个类型,然后设置值,在下面的示例中,
North
被设置为
100
,其余的将是
101
102
等,就像在
C
Objective-C
中一样

enum CompassPoint: Int {
    case North = 100, South, East, West
}

let rawNorth = CompassPoint.North.rawValue // => 100
let rawSouth = CompassPoint.South.rawValue // => 101
// etc.

更新:将
toRaw()
替换为
rawValue

请阅读此希望,这可能会解决您的困惑。
toRaw()
已替换为
rawValue
谢谢提醒,nacho4d。我已经更新了答案,并对更改做了简短的评论。@fnc12:没有Swift 2.3…