在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'
从raw使用带有rawValue的failable初始化器创建枚举,并使用属性rawValue获取原始值。
原文链接:https://www.f2er.com/swift/320994.htmlif let a = TestEnum(rawValue: "a") { println(a.rawValue) }
有关详细信息,请阅读the changelog。