我有以下列举。
enum EstimateItemStatus: Printable {
case Pending
case OnHold
case Done
var description: String {
switch self {
case .Pending: return "Pending"
case .OnHold: return "On Hold"
case .Done: return "Done"
}
}
init?(id : Int) {
switch id {
case 1:
self = .Pending
case 2:
self = .OnHold
case 3:
self = .Done
default:
return nil
}
}
}
我需要将所有原始值获取为字符串数组(例如["Pending", "On Hold", "Done"]
)。
我将此方法添加到枚举中。
func toArray() -> [String] {
var n = 1
return Array(
GeneratorOf<EstimateItemStatus> {
return EstimateItemStatus(id: n++)!.description
}
)
}
但我收到以下错误。
找不到类型'GeneratorOf'的初始化程序,该初始化程序接受类型'(()-> _)'的参数列表
有没有更简单,更好或更优雅的方式来做到这一点?