Skip to content

Instantly share code, notes, and snippets.

@polac24
Last active August 30, 2017 10:46
Show Gist options
  • Save polac24/f33791151e22d4787a09262d66f01bcd to your computer and use it in GitHub Desktop.
Save polac24/f33791151e22d4787a09262d66f01bcd to your computer and use it in GitHub Desktop.
Enum with Int
enum Cases: Int {
case myCase = 1
case myOtherCase
// custom value breaks this workaround
// case usafeCase = 300
static var allCases: [Cases] {
var values: [Cases] = []
var index = 1
while let element = self.init(rawValue: index) {
values.append(element)
index += 1
}
return values
}
}
let arrayCasses = Cases.allCases
extension Cases{
var stringRepresentation:String {
switch(self){
case .myCase: return "my_case"
case .myOtherCase: return "my_other_case"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment