在我的场景中,我希望使用数字值作为枚举大小写键值。我怎样才能做到这一点呢?
我试过了
enum Order: String {
case "1" : "Mobiles"
case "2" : "Automotive"
}有没有办法写出类似的代码?
我知道其他方式可以很好地工作(情况手机:"1“,情况汽车:"2”),但我需要在这种方式。
发布于 2017-07-11 04:12:37
我不认为有一种方法可以做你想做的事情,但你可以这样做:
enum Order: String {
case order1 : "Mobiles"
case order2 : "Automotive"
}或者,您可以简单地使用静态字符串数组:
struct Constants
{
static let orders = ["Mobiles","Automotive"]
}并在其下标上一个数值:
Constants.orders[1]https://stackoverflow.com/questions/45020692
复制相似问题