ฉันมี enum ดังต่อไปนี้
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"]
)
ฉันเพิ่มวิธีนี้ลงใน enum
func toArray() -> [String] {
var n = 1
return Array(
GeneratorOf<EstimateItemStatus> {
return EstimateItemStatus(id: n++)!.description
}
)
}
แต่ฉันได้รับข้อผิดพลาดต่อไปนี้
ไม่พบตัวเริ่มต้นสำหรับประเภท 'GeneratorOf' ที่ยอมรับรายการอาร์กิวเมนต์ประเภท '(() -> _)'
มีวิธีที่ง่ายกว่าดีกว่าหรือสวยงามกว่านี้ไหม?