我有我的模型UISegmentedControl。我有一个错误,我enum不知道它是什么。
在我的SegmentedControl我想要:索引 0 = 1(Int) 索引 1 = 2(Int).....
我的代码和我对链接的看法。

您的枚举中不需要逗号。如果你想要一个 Int 枚举,你应该写
enum MamsEntreeGout: Int {
case firstValue = 1
case secondValue = 2
case thirdValue = 3
case fourthValue = 4
}
另一个枚举也是如此。
享受
在Swift您不能直接将Int值定义为enum's case,即以下enum内容无效。
enum MamsEntreeGout {
case 1
}
相反,您应该创建一个enum's cases与 相同syntax的variables,即
enum MamsEntreeGout {
case first
}
在Swift,在其他语言enum's cases中没有任何相似之处。default values因此,如果您想将 thecases与 any关联value,则必须指定 a Raw Type,即
enum MamsEntreeGout: Int {
case first
}
在上面的代码中,Int是Raw Type.enum MamsEntreeGout
当整数用于原始值时,每种情况的隐含值比前一种情况多一个。如果第一种情况没有设置值,则其值为 0。
因此,如果有as ,则无需values为每个定义。caseenumRaw TypeInt
所以,你可以定义你的enums喜欢:
enum MamsEntreeGout: Int {
case first = 1, second, third, fourth
}
, separated cases绝对允许进入Swift。
使用访问Int任何 of 的cases值,即enumrawValuecase name
MamsEntreeGout.third.rawValue
The identifiers in an enum can not be or start with a number, it has to be a letter (a-z, A-Z) an underscore or some unicode characters, see https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#grammar_identifier-head
So
enum bad {
case 1, 2word, 3.0
}
is not allowed but
enum good {
case a1, _2, treedotzero
}
will work fine