I'm doing todo in Swift using diffable data source.
private var todos = [[ToDoItem]]() // my dataSource
enum Section { // my sections
case unfulfilled
case completed
}
By clicking on the knockout that is on the task, the task itself should move from the unfulfilled section to completed.
I was also told to use the method with two arrays.
That is, I have my usual datasource, where will todo get to, tell me how to make sure that I have a second branch that is responsible for the second section, or how to solve this problem in general.
An example of my old code:
func configureSnapshot() {
var snapshot = Snapshot()
if todos.isEmpty { return }
if todos.count == 1 {
if todos.first!.first!.isCompleted {
snapshot.appendSections([.completed])
snapshot.appendItems(todos.first!, toSection: .completed)
} else {
snapshot.appendSections([.unfulfilled])
snapshot.appendItems(todos.first!, toSection: .unfulfilled)
}
} else if todos.count == 2 {
snapshot.appendSections([.unfulfilled, .completed])
snapshot.appendItems(todos.first!, toSection: .unfulfilled)
snapshot.appendItems(todos[1], toSection: .completed)
}
dataSource?.apply(snapshot, animatingDifferences: true)
}
I don't remember the number of their attempts anymore. There were enough of them to tell me to use two arrays.