CollectionSectionViewModel

public struct CollectionSectionViewModel : DiffableViewModel

View model for a collection view section.

  • The key used by the diffing algorithm to uniquely identify this section. If you are using automatic diffing on the CollectionViewDriver (which is enabled by default) you are required to provide a key that uniquely identifies this section.

    Typically you want to base this diffing key on data that is stored in the model. For example:

     public var diffingKey = { group.identifier }
    

    Declaration

    Swift

    public var diffingKey: String
  • Returns true if this section has zero cell view models, false otherwise.

    Declaration

    Swift

    public var isEmpty: Bool { get }
  • Initializes a collection view section view model.

    Declaration

    Swift

    public init(
        diffingKey: String?,
        cellViewModels: [CollectionCellViewModel],
        headerViewModel: CollectionSupplementaryViewModel? = nil,
        footerViewModel: CollectionSupplementaryViewModel? = nil
    )

    Parameters

    diffingKey

    a String key unique to this section that is used to diff sections automatically. Pass in nil if you are not using automatic diffing on this collection.

    cellViewModels

    the cells in this section.

    headerViewModel

    the header view model (defaults to nil).

    footerViewModel

    the footer view model (defaults to nil).