Created
February 1, 2018 05:25
-
-
Save dermotos/93a1858c1f58f946feb3a3363ae9f3e8 to your computer and use it in GitHub Desktop.
Protocol pattern for allowing an Enum to list all its cases
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol ListableEnumeration { | |
associatedtype T | |
static var allItems :[T] { get } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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