0

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)
}

enter image description here

I don't remember the number of their attempts anymore. There were enough of them to tell me to use two arrays.

HangarRash
  • 7,314
  • 5
  • 5
  • 32
Desalutar
  • 1
  • 2
  • What exactly are you asking? It's not clear from the question. Whatever it is, using nested arrays seems a strange approach. Two separate arrays would be much clearer. (and the force unwrap will cause a crash when the array of incomplete tasks is empty) – flanker Aug 22 '23 at 14:26

0 Answers0