我正在尝试实现这样的字符串数组的枚举
import UIKit
enum EstimateItemStatus: Int, [String] {
case Pending
case OnHold
case Done
var description: [String] {
switch self {
case .Pending:
return ["one", "Two"]
case .OnHold:
return ["one", "Two"]
case .Done:
return ["one", "Two"]
}
}
}
print(EstimateItemStatus.Pending.description)
但我收到此错误:
error: processArray.playground:3:31: error: multiple enum raw types 'Int' and '[String]'
enum EstimateItemStatus: Int, [String] {
~~~ ^
你们谁都知道如何解决此错误以使枚举起作用?
非常感谢您的帮助。
最佳答案
从枚举声明中删除[String]
。
enum EstimateItemStatus: Int {
case Pending
case OnHold
case Done
var description: [String] {
switch self {
case .Pending:
return ["one", "Two"]
case .OnHold:
return ["one", "Two"]
case .Done:
return ["one", "Two"]
}
}
}
关于ios - Swift:如何实现字符串数组的枚举,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61552648/