Skip to content

Instantly share code, notes, and snippets.

@EricADockery
Created February 7, 2018 22:36
Show Gist options
  • Save EricADockery/521e83ba819dc08228e4db221c035c13 to your computer and use it in GitHub Desktop.
Save EricADockery/521e83ba819dc08228e4db221c035c13 to your computer and use it in GitHub Desktop.
Example to creating multiple titles for headers in section given different layout options
enum SectionTitle: String {
case a = "a"
case b = "b"
case c = "c"
case d = "d"
init?(section: Int, hasB: Bool = false, hasD: Bool = false) {
if hasD {
switch section {
case 0: self = .a
case 1: self = .b
case 2: self = .c
case 3: self = .d
default: return nil
}
} else {
switch section {
case 0: self = .a
case 1:
if hasB {
self = .b
} else {
self = .c
}
case 2:
self = .c
default: return nil
}
}
}
}
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
let hasB = true
let hasD = false
let title = SectionTitle(section: section, hasB: hasB, hasD: hasD)
return title?.rawValue ?? ""
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment