I'm trying to use an enum to categorize the various sections in a
UITableView
enum
enum Section: Int, CustomStringConvertible {
case open = 0
case closed = 1
var description: String {
switch self {
case .open:
return "Open"
case .closed:
return "Closed"
}
}
}
UITableView
override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return Section(rawValue: section)?.description
}
UIColors
case
If all you're trying to do is set up a correspondence between numbers and strings:
0 -> Open
1 -> Closed
... then it's hard to see what the enum is for. What you want is a dictionary where the numbers are keys, or even just a simple array:
let arr = ["Open", "Closed"]
In the array, the string is indexed by the numbers:
return arr[rawValue: section]