CellViewModel

@MainActor
public protocol CellViewModel : DiffableViewModel, ViewRegistrationProvider

Defines a view model that describes and configures a cell in the collection view.

  • The type of cell that this view model represents and configures.

    Declaration

    Swift

    associatedtype CellType : UICollectionViewCell
  • shouldHighlight Default implementation

    Returns whether or not the cell should get highlighted. This corresponds to the delegate method collectionView(_:shouldHighlightItemAt:). The default implementation returns true.

    Default Implementation

    Default implementation. Returns true.

    Declaration

    Swift

    var shouldHighlight: Bool { get }
  • contextMenuConfiguration Default implementation

    Returns a context menu configuration for the cell. This corresponds to the delegate method collectionView(_:contextMenuConfigurationForItemAt:point:).

    Default Implementation

    Default implementation. Returns nil.

    Declaration

    Swift

    var contextMenuConfiguration: UIContextMenuConfiguration? { get }
  • Configures the provided cell for display in the collection.

    Declaration

    Swift

    func configure(cell: CellType)

    Parameters

    cell

    The cell to configure.

  • didSelect(with:) Default implementation

    Handles the selection event for this cell, optionally using the provided coordinator.

    Default Implementation

    Default implementation. Calls didSelectCell(viewModel:) on the coordinator, passing self to the viewModel parameter.

    Declaration

    Swift

    func didSelect(with coordinator: CellEventCoordinator?)

    Parameters

    coordinator

    An event coordinator object, if one was provided to the CollectionViewDriver.

  • cellClass Extension method

    The cell class for this view model.

    Declaration

    Swift

    public var cellClass: AnyClass { get }
  • reuseIdentifier Extension method

    A default reuse identifier for cell registration. Returns the name of the class implementing the CellViewModel protocol.

    Declaration

    Swift

    public var reuseIdentifier: String { get }
  • registration Extension method

    A default registration for this view model for class-based cells.

    Warning

    Does not work for nib-based cells.

    Declaration

    Swift

    public var registration: ViewRegistration { get }
  • eraseToAnyViewModel() Extension method

    Returns a type-erased version of this view model.

    Declaration

    Swift

    public func eraseToAnyViewModel() -> AnyCellViewModel