TableSectionViewModel

public struct TableSectionViewModel

View model for a table view section.

  • Cells to be shown in this section.

    Declaration

    Swift

    public let cellViewModels: [TableCellViewModel]
  • View model for the header of this section.

    Declaration

    Swift

    public let headerViewModel: TableSectionHeaderFooterViewModel?
  • View model for the footer of this section.

    Declaration

    Swift

    public let footerViewModel: TableSectionHeaderFooterViewModel?
  • Indicates whether or not this section is collapsed.

    Declaration

    Swift

    public var collapsed: Bool
  • The key used by the diffing algorithm to uniquely identify this section. If you are using automatic diffing on the TableViewDriver (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 is the section is empty, false otherwise.

    Declaration

    Swift

    public var isEmpty: Bool { get }
  • Initializes a TableViewSectionViewModel.

    Declaration

    Swift

    public init(
        cellViewModels: [TableCellViewModel],
        headerViewModel: TableSectionHeaderFooterViewModel? = nil,
        footerViewModel: TableSectionHeaderFooterViewModel? = nil,
        collapsed: Bool = false,
        diffingKey: String? = nil
    )

    Parameters

    cellViewModels

    the cell view models contained in this section.

    headerViewModel

    a header view model for this section (defaults to nil).

    footerViewModel

    a footer view model for this section (defaults to nil).

    collapsed

    whether or not this section is collapsed (defaults to false).

    diffingKey

    the diffing key, or nil. Required for automated diffing.

  • Initializes a TableViewSectionViewModel.

    Declaration

    Swift

    public init(
        headerTitle: String?,
        headerHeight: CGFloat?,
        cellViewModels: [TableCellViewModel],
        footerTitle: String? = nil,
        footerHeight: CGFloat? = 0,
        diffingKey: String? = nil
    )

    Parameters

    headerTitle

    title for the header, or nil. Setting a title will cause a default header to be added to this section.

    headerHeight

    the height of the default header, if one exists.

    cellViewModels

    the cell view models contained in this section.

    footerTitle

    title for the footer, or nil. Setting a title will cause a default footer to be added to this section.

    footerHeight

    the height of the default footer, if one exists.

    diffingKey

    the diffing key, or nil. Required for automated diffing.