This what I have to do:
enum ItemKind : Int {
case All
case Mine
case InUse
case Archive
static let all = [ItemKind.All, ItemKind.Mine, ItemKind.InUse, ItemKind.Archive]
static let strings = ["All", "Mine", "In Use", "Archive"]
static let values:[String:ItemKind] = [
strings[ItemKind.All.rawValue]: ItemKind.All
, strings[ItemKind.Mine.rawValue]: ItemKind.Mine
, strings[ItemKind.InUse.rawValue]: ItemKind.InUse
, strings[ItemKind.Archive.rawValue]: ItemKind.Archive
]
var description: String {
return ItemKind.strings[self.rawValue]
}
}
This what I would like to do:
enum ItemKind : Int {
case All
case Mine
case InUse
case Archive
static let all = [ItemKind.All, ItemKind.Mine, ItemKind.InUse, ItemKind.Archive]
static let strings = ["All", "Mine", "In Use", "Archive"]
static let values:[String:ItemKind] = all.map {
/// ???
($0.description, $0)
/// ??? or something
}
var description: String {
return ItemKind.strings[self.rawValue]
}
}
Anyway to tweak the latter such that I can avoid hard-coding the dictionary values as I am forced to do in the former?
I had a look at Dictionary.generate but this an instance method and I would need a static one. Or at least an initializer.
(for unrelated reasons I need the `ItemKind` enum to based off `Int` not `String`)