enum Num: String{
case Zero = "0", One = "1", Two = "2", Three = "3", Four = "4", Five = "5", Six = "6", Seven = "7", Eight = "8", Nine = "9", Ten = "10", Eleven = "11", Twelve = "12"
}
このようなenumがあった場合にfor inさせるにはどのような方法がありますか?
少し違うかもしれませんが、英語版で似た質問を見つけました。
https://stackoverflow.com/questions/24007461/how-to-enumerate-an-enum-with-string-type
// 英語版から転載
enum ProductCategory : String {
case Washers = "washers", Dryers = "dryers", Toasters = "toasters"
static let allValues = [Washers, Dryers, Toasters]
}
for category in ProductCategory.allValues{
//Do something
}