在 Xcode 6.1 中,枚举 toRaw
和 fromRaw
函数不再起作用:
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'
最佳答案
使用带有 rawValue
的可失败初始化器从原始创建枚举,并使用属性 rawValue
获取原始值。
if let a = TestEnum(rawValue: "a") {
println(a.rawValue)
}
阅读the changelog获取更多信息。
关于enums - 使用 Xcode 6.1 的 Swift 枚举 .toRaw 和 .fromRaw,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25919075/