CollectionViewModel

public struct CollectionViewModel : DiffableViewModel
extension CollectionViewModel: Collection, RandomAccessCollection
extension CollectionViewModel: CustomDebugStringConvertible

Represents a collection view with sections and items.

  • Returns the empty collection view model.

    Declaration

    Swift

    public static var empty: `Self` { get }

DiffableViewModel

Properties

Init

Accessing Sections

  • Returns the section for the specified id.

    Declaration

    Swift

    public func sectionViewModel(for id: UniqueIdentifier) -> SectionViewModel?

    Parameters

    id

    The identifier for the section.

    Return Value

    The section, if it exists.

  • Returns the section at the specified index.

    Precondition

    The specified index must be valid.

    Declaration

    Swift

    public func sectionViewModel(at index: Int) -> SectionViewModel

    Parameters

    index

    The index of the section.

    Return Value

    The section at index.

Accessing Cells

  • Returns the cell for the specified id.

    Declaration

    Swift

    public func cellViewModel(for id: UniqueIdentifier) -> AnyCellViewModel?

    Parameters

    id

    The identifier for the cell.

    Return Value

    The cell, if it exists.

  • Returns the cell at the specified index path.

    Precondition

    The specified indexPath must be valid.

    Declaration

    Swift

    public func cellViewModel(at indexPath: IndexPath) -> AnyCellViewModel

    Parameters

    indexPath

    The index path of the cell.

    Return Value

    The cell at indexPath.

Accessing Supplementary Views

  • Returns the supplementary view for the specified id.

    Declaration

    Swift

    public func supplementaryViewModel(for id: UniqueIdentifier) -> AnySupplementaryViewModel?

    Parameters

    id

    The identifier for the supplementary view.

    Return Value

    The supplementary view, if it exists.

  • Returns the supplementary view for the specified kind and index path.

    Precondition

    The specified indexPath must be valid.

    Declaration

    Swift

    public func supplementaryViewModel(ofKind kind: String, at indexPath: IndexPath) -> AnySupplementaryViewModel?

    Parameters

    kind

    The kind of the supplementary view.

    indexPath

    The index path for the view.

    Return Value

    The supplementary view.

Subscript

  • Returns the cell at the specified index path.

    Precondition

    The specified indexPath must be valid.

    Declaration

    Swift

    public subscript(indexPath: IndexPath) -> AnyCellViewModel { get }

    Parameters

    indexPath

    The index path of the cell.

    Return Value

    The cell at indexPath.

  • Returns the cell at the specified indexes.

    Precondition

    The specified indexes must be valid.

    Declaration

    Swift

    public subscript(item item: Int, section section: Int) -> AnyCellViewModel { get }

    Parameters

    item

    The item index of the cell.

    section

    The section index of the cell.

    Return Value

    The cell at item and section.