How to enumerate an enum with String type?

This post is relevant here https://www.swift-studies.com/blog/2014/6/10/enumerating-enums-in-swift

Essentially the proposed solution is

enum ProductCategory : String {
     case Washers = "washers", Dryers = "dryers", Toasters = "toasters"

     static let allValues = [Washers, Dryers, Toasters]
}

for category in ProductCategory.allValues{
     //Do something
}

Leave a Comment