You might find this interesting:
Using the protocol of CaseIterable in the enum SectionType as in
enum SectionType: String, CaseIterable {
case ceo = "CEO"
case peasants = "Peasants"
}
allows the use of SectionType.allcases in:
1) func setupSouce
private func setupSource() {
var snapshot = source.snapshot()
snapshot.appendSections(SectionType.allCases) // append all section types
snapshot.appendItems([
.init(name: "Elon Musk"),
.init(name: "Tim Cook"),
.init(name: "Jeff Bezos")
], toSection: .ceo)
snapshot.appendItems([
.init(name: "Bill Gates")
], toSection: .peasants)
source.apply(snapshot)
}
2) and when rendering table section headers:
override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let label = UILabel()
label.text = SectionType.allCases[section].rawValue // Set header title from SectionType case
return label
}