Swift枚举.toRaw和.fromRaw与Xcode 6.1 [英] Swift Enumerations .toRaw and .fromRaw with Xcode 6.1

查看:170
本文介绍了Swift枚举.toRaw和.fromRaw与Xcode 6.1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Xcode 6.1中,枚举 toRaw fromRaw 函数不再工作:

In Xcode 6.1, the enumerations toRaw and fromRaw functions don't work anymore:

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

Create an enum from a raw using the failable initializer with rawValue and get the raw value using the attribute rawValue.

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

阅读更改日志获取更多信息。

这篇关于Swift枚举.toRaw和.fromRaw与Xcode 6.1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆