Skip to content

Instantly share code, notes, and snippets.

@nahive
Last active February 16, 2017 13:31
Show Gist options
  • Save nahive/20e27b4a3f0fb290678eba310ce2089b to your computer and use it in GitHub Desktop.
Save nahive/20e27b4a3f0fb290678eba310ce2089b to your computer and use it in GitHub Desktop.
Example of handling sections in UITableView
enum Section: Int {
case robots = 0
case cats
case dogs
case humans
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
switch Section(rawValue: section) {
case .robots?: // return rows count
case .cats?: // return rows count
case .dogs?: // return rows count
case .humans?: // return rows count
default: fatalError()
}
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
switch Section(rawValue: indexPath.section) {
case .robots?: // dequeue cell
case .cats?: // dequeue cell
case .dogs?: // dequeue cell
case .humans?: // dequeue cell
default: fatalError()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment