ra1028 / DifferenceKit

💻 A fast and flexible O(n) difference algorithm framework for Swift collection.
https://ra1028.github.io/DifferenceKit
Apache License 2.0
3.54k stars 239 forks source link

handle multiple sections #116

Open J-Arji opened 4 years ago

J-Arji commented 4 years ago

I want my tableview handle multiple sections with different Items.

my model is :

struct Object: Hashable, Comparable, Equatable {

    var index: Int
    var name: String

    var data: [Any]
}

and Object is section and data is row of cell

I went this way:

extension Object: Differentiable {

    var differenceIdentifier: String {
        return "\(index)"
    }

    func isContentEqual(to source: TypeStorableItem) -> Bool {
        index == source.index && name == source.name
    }
}

and in ViewController :

typealias AnyArraySection =  ArraySection<TypeStorableItem, AnyDifferentiable>

  var typeManager: [AnyArraySection] = []
    var inputTypeManager: [AnyArraySection] {
        get { typeManager }
        set {
            let changeset = StagedChangeset(source: typeManager, target: newValue)

            self.tableView.reload(using: changeset, with: .automatic) { data in
                self.typeManager = data
            }
        }
    }

when I want add item

let model = Object(index: index,
                                       name: identifier,
                                       data: data)
        item = ArraySection(model: model, elements: model.data)

how is it possible? what about multiple sections with multiple types.

Detailed Description (Include Screenshots)

Environment