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 implementationReturns whether or not the cell should get highlighted. This corresponds to the delegate method
collectionView(_:shouldHighlightItemAt:)
. The default implementation returnstrue
.Default Implementation
Default implementation. Returns
true
.Declaration
Swift
var shouldHighlight: Bool { get }
-
contextMenuConfiguration
Default implementationReturns 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 thecoordinator
, passingself
to theviewModel
parameter.Declaration
Swift
func didSelect(with coordinator: CellEventCoordinator?)
Parameters
coordinator
An event coordinator object, if one was provided to the
CollectionViewDriver
. -
cellClass
Extension methodThe cell class for this view model.
Declaration
Swift
public var cellClass: AnyClass { get }
-
reuseIdentifier
Extension methodA 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 methodA 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 methodReturns a type-erased version of this view model.
Declaration
Swift
public func eraseToAnyViewModel() -> AnyCellViewModel