Structures

The following structures are available globally.

  • An ordered collection of Changeset as staged set of changes in the sectioned collection.

    The order is representing the stages of changesets.

    We know that there are combination of changes that crash when applied simultaneously in batch-updates of UI such as UITableView or UICollectionView. The StagedChangeset created from the two collection is split at the minimal stages that can be perform batch-updates with no crashes.

    Example for calculating differences between the two linear collections.

    extension String: Differentiable {}
    
    let source = ["A", "B", "C"]
    let target = ["B", "C", "D"]
    
    let changeset = StagedChangeset(source: source, target: target)
    print(changeset.isEmpty)  // prints "false"
    

    Example for calculating differences between the two sectioned collections.

    let source = [
        Section(model: "A", elements: ["😉"]),
    ]
    let target = [
        Section(model: "A", elements: ["😉, 😺"]),
        Section(model: "B", elements: ["😪"])
    ]
    
    let changeset = StagedChangeset(source: sectionedSource, target: sectionedTarget)
    print(changeset.isEmpty)  // prints "false"
    
    See more

    Declaration

    Swift

    public struct StagedChangeset<Collection> where Collection : Collection
  • A type-erased differentiable value.

    The AnyDifferentiable type hides the specific underlying types. Associated type DifferenceIdentifier is erased by AnyHashable. The comparisons of whether has updated is forwards to an underlying differentiable value.

    You can store mixed-type elements in collection that require Differentiable conformance by wrapping mixed-type elements in AnyDifferentiable:

    extension String: Differentiable {}
    extension Int: Differentiable {}
    
    let source = [
        AnyDifferentiable("ABC"),
        AnyDifferentiable(100)
    ]
    let target = [
        AnyDifferentiable("ABC"),
        AnyDifferentiable(100),
        AnyDifferentiable(200)
    ]
    
    let changeset = StagedChangeset(source: source, target: target)
    print(changeset.isEmpty)  // prints "false"
    
    See more

    Declaration

    Swift

    public struct AnyDifferentiable : Differentiable
  • A differentiable section with model and array of elements.

    Arrays are can not be identify each one and comparing whether has updated from other one. ArraySection is a generic wrapper to hold a model to allow it.

    See more

    Declaration

    Swift

    public struct ArraySection<Model, Element> : DifferentiableSection where Model : Differentiable, Element : Differentiable
  • A set of changes in the sectioned collection.

    Changes to the section of the linear collection should be empty.

    Notice that the value of the changes represents offsets of collection not index. Since offsets are unordered, order is ignored when comparing two Changesets.

    See more

    Declaration

    Swift

    public struct Changeset<Collection> where Collection : Collection
  • Represents the path to a specific element in a tree of nested collections.

    Note

    Foundation.IndexPath is disadvantageous in performance.
    See more

    Declaration

    Swift

    public struct ElementPath : Hashable