如何使用[](如Numbers [“ one”])访问枚举:
enum Numbers: String {
case one = "1"
case two = "2"
case three = "3"
}
print(Numbers["one"])
答案 0 :(得分:1)
let access_num = Numbers.two
print(access_num.rawValue)
// prints "2"
或
enum Numbers: Int {
case one = 1, two , three , four
}
var access_num = Numbers(rawValue: 2)!
print(access_num)
答案 1 :(得分:0)
也许您是说rawValue吗?
print(Numbers(rawValue:"1"))
答案 2 :(得分:0)
您可以像这样访问其字符串值:
print(Numbers.one.rawValue)。 //输出:-“ 1 / n”