一尘不染

使用Xcode 6.1的Swift枚举.toRaw和.fromRaw

swift

在Xcode 6.1中,枚举toRawfromRaw函数不再起作用:

enum TestEnum : String {
    case A = "a"
    case B = "b"
}

if let a = TestEnum.fromRaw("a") {
    prinln(a.toRaw())
}

错误:

'TestEnum' does not have a member named 'toRaw'
'TestEnum.Type' does not have a member named 'fromRaw'

阅读 466

收藏
2020-07-07

共1个答案

一尘不染

使用失败的初始化器从原始创建枚举,rawValue并使用属性获取原始值rawValue

if let a = TestEnum(rawValue: "a") {
     println(a.rawValue)
}

阅读变更日志以获取更多信息。

2020-07-07