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
| func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { | |
| let (value, reusableId) = self.values[indexPath.section].rows[indexPath.row] | |
| let cell = tableView.dequeueReusableCell(withIdentifier: reusableId, for: indexPath) | |
| switch (cell, value) { | |
| case (_ as ProfileTableViewCell, _ as Void): break | |
| case let (cell as TaskTableViewCell, value as Task): | |
| cell.configure(with: value) | |
| default: break | |
| } |
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
| func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? { | |
| return values[section].headerTitle | |
| } |
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
| func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { | |
| return values[section].rows.count | |
| } |
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
| func numberOfSections(in tableView: UITableView) -> Int { | |
| return values.count | |
| } |
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 CommonizedDataSource: NSObject, UITableViewDataSource { | |
| private var values: [(headerTitle: String?, rows: [(value: Any, reusableId: String)])] = [] | |
| func load(_ tasks: [Task]) { | |
| self.values = [ | |
| ( | |
| headerTitle: nil, | |
| rows: [(value: (), reusableId: "ProfileTableViewCell")] | |
| ), |
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
| func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? { | |
| switch section { | |
| case 0: | |
| return nil | |
| case 1: | |
| return Category.personal.rawValue | |
| case 2: | |
| return Category.shopping.rawValue | |
| case 3: | |
| return Category.work.rawValue |
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
| func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { | |
| switch indexPath.section { | |
| case 0: | |
| return tableView.dequeueReusableCell(withIdentifier: "ProfileTableViewCell") as! ProfileTableViewCell | |
| case 1: | |
| let cell = tableView.dequeueReusableCell(withIdentifier: "TaskTableViewCell") as! TaskTableViewCell | |
| let personalTask = tasks.filter { $0.category == .personal }[indexPath.row] | |
| cell.configure(with: personalTask) | |
| return cell | |
| case 2: |
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
| func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { | |
| switch section { | |
| case 0: | |
| return 1 | |
| case 1: | |
| return tasks.filter { $0.category == .personal }.count | |
| case 2: | |
| return tasks.filter { $0.category == .shopping }.count | |
| case 3: | |
| return tasks.filter { $0.category == .work }.count |
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
| func numberOfSections(in tableView: UITableView) -> Int { | |
| return Category.allCases.count + 1 | |
| } |
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 SimpleDataSource: NSObject, UITableViewDataSource { | |
| private var tasks: [Task] = [] | |
| func load(with tasks: [Task]) { | |
| self.tasks = tasks | |
| } | |
| . | |
| . | |
| . |