Skip to content

Instantly share code, notes, and snippets.

@rockname
Created December 3, 2018 09:30
Show Gist options
  • Select an option

  • Save rockname/1abefdfb8b4c71ba96a47514ef46aacd to your computer and use it in GitHub Desktop.

Select an option

Save rockname/1abefdfb8b4c71ba96a47514ef46aacd to your computer and use it in GitHub Desktop.
class GeneralizedDataSource: StructuredTableCellDataSource {
func load(_ tasks: [Task]) {
let profileSection = TableCellSection(rows: [TableCellRow(reusableId: "ProfileTableViewCell", value: ())])
let personalTaskSection = TableCellSection(
rows: tasks.filter { $0.category == .personal }.map { TableCellRow(reusableId: "TaskTableViewCell", value: $0) },
headerTitle: Category.personal.rawValue
)
let shoppingTaskSection = TableCellSection(
rows: tasks.filter { $0.category == .shopping }.map { TableCellRow(reusableId: "TaskTableViewCell", value: $0) },
headerTitle: Category.shopping.rawValue
)
let workTaskSection = TableCellSection(
rows: tasks.filter { $0.category == .work }.map { TableCellRow(reusableId: "TaskTableViewCell", value: $0) },
headerTitle: Category.work.rawValue
)
[profileSection, personalTaskSection, shoppingTaskSection, workTaskSection].forEach(appendSection)
}
override func configureCell(_ cell: UITableViewCell, withValue value: Any) {
switch (cell, value) {
case (_ as ProfileTableViewCell, _ as Void): break
case let (cell as TaskTableViewCell, value as Task):
cell.configure(with: value)
default: fatalError()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment