Created
December 3, 2018 09:30
-
-
Save rockname/1abefdfb8b4c71ba96a47514ef46aacd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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