Skip to content

Instantly share code, notes, and snippets.

@rockname
Created December 3, 2018 08:58
Show Gist options
  • Select an option

  • Save rockname/7a2945d1f7c0c9079ae5d2f0bea3af9d to your computer and use it in GitHub Desktop.

Select an option

Save rockname/7a2945d1f7c0c9079ae5d2f0bea3af9d to your computer and use it in GitHub Desktop.
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")]
),
(
headerTitle: Category.personal.rawValue,
rows: tasks.filter { $0.category == .personal }.map { (value: $0, reusableId: "TaskTableViewCell") }
),
(
headerTitle: Category.shopping.rawValue,
rows: tasks.filter { $0.category == .personal }.map { (value: $0, reusableId: "TaskTableViewCell") }
),
(
headerTitle: Category.work.rawValue,
rows: tasks.filter { $0.category == .personal }.map { (value: $0, reusableId: "TaskTableViewCell") }
)
] as! [(headerTitle: String?, rows: [(value: Any, reusableId: String)])]
}
.
.
.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment