Last active
August 30, 2017 10:46
-
-
Save polac24/f33791151e22d4787a09262d66f01bcd to your computer and use it in GitHub Desktop.
Enum with Int
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 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