DifferenceKit icon indicating copy to clipboard operation
DifferenceKit copied to clipboard

handle multiple sections

Open J-Arji opened this issue 4 years ago • 0 comments

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

  • Library version:

  • Swift version:

  • iOS version: 13

  • Xcode version: 11.7

  • Devices/Simulators:

  • CocoaPods/Carthage version:

J-Arji avatar Sep 11 '20 10:09 J-Arji