I have a game program (in Swift) that uses a textfile to define each game (currently 90 of them). The textfile is NOT XML or JSON, just key/value pairs for the most part…
public enum ruleGAME : Int {
case noRULE = -1
case kBlank = 0
case diffNOWRAP = 206
case diffWRAP = 207
case rankORdiff = 208
case rowORcol = 209
The problem is the value 209 which is ‘ruleGame’ in the textfile, is ‘rowORcol’ in the enum
when creating the textfiles I have to always refer to the code to get the correct values. What I would like to do is be able to leave the ENUM as it is, but change the text file
From
ruleGAME = 209
to
ruleGAME = rowORCol
the only way I can think to do this is create a dictionary, but that seems excessive, there should be a way to utilize the existing Enum
public enum ruleGAME: String {
case noRULE = "noRULE"
case kBlank = "kBlank"
case diffNOWRAP = "diffNOWRAP"
case diffWRAP = "diffWRAP"
case rankORdiff = "rankORdiff"
case rowORcol = "rowORcol"
}
Then use the rawValue property to make comparisons or assignments?
if thisGameRuleValueAsString == ruleGAME.rowORcol.rawValue {
// do something special
}
that actually could work… the reason it is numbers is that it all started when I ported an ancient DOS game years and years ago… it has been updated many time and this version is the first to actually be in the App Store.