使用 int 作为枚举中的情况

Jam*_*ner 6 int enums swift

我正在处理一些基本的 Swift 操作。我想使用滑块指定相应的标签。由于滑块使用 anint来表示位置,因此我将使用枚举进行转换。

enum Temperature: Int {
   case 0 = "Zero"
   case 1 = "One"
   case 2 = "Two"
   case 3 = "Three"
}
Run Code Online (Sandbox Code Playgroud)

我想这样称呼它:

variable = Temperature.0
Run Code Online (Sandbox Code Playgroud)

任何帮助都是理想的。请让我知道你的想法。

谢谢!

Kam*_*xom 2

您可以使用数组:

let temperatures = ["Zero", "One", "Two", "Three"]

let one = temeratures[1]
Run Code Online (Sandbox Code Playgroud)

或者一个元组:

let temperatures = ("Zero", "One", "Two", "Three")

let one = temperatures.1
Run Code Online (Sandbox Code Playgroud)

而您不能在后者中使用运行时值(非文字)