Skip to content

Instantly share code, notes, and snippets.

@dermotos
Created February 1, 2018 05:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dermotos/93a1858c1f58f946feb3a3363ae9f3e8 to your computer and use it in GitHub Desktop.
Save dermotos/93a1858c1f58f946feb3a3363ae9f3e8 to your computer and use it in GitHub Desktop.
Protocol pattern for allowing an Enum to list all its cases
protocol ListableEnumeration {
associatedtype T
static var allItems :[T] { get }
}
enum MyEnum : ListableEnumeration {
case firstCase
case secondCase
typealias T = MyEnum
static var allItems:[MyEnum] {
return [.firstCase, .secondCase]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment