CellViewModel
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
-
shouldSelect
Default implementationReturns whether or not the cell should get selected. This corresponds to the delegate method
collectionView(_:shouldSelectItemAt:)
. The default implementation returnstrue
.Default Implementation
Default implementation. Returns
true
.Declaration
Swift
var shouldSelect: Bool { get }
-
shouldDeselect
Default implementationReturns whether or not the cell should get deselected. This corresponds to the delegate method
collectionView(_:shouldDeselectItemAt:)
. The default implementation returnstrue
.Default Implementation
Default implementation. Returns
true
.Declaration
Swift
var shouldDeselect: Bool { get }
-
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
@MainActor func configure(cell: CellType)
Parameters
cell
The cell to configure.
-
didSelect(with:
Default implementation) Tells the view model that its cell was selected.
Implement this method to handle this event, optionally using the provided
coordinator
.Default Implementation
Default implementation. Calls
didSelectCell(viewModel:)
on thecoordinator
, passingself
to theviewModel
parameter.Declaration
Swift
@MainActor func didSelect(with coordinator: CellEventCoordinator?)
Parameters
coordinator
An event coordinator object, if one was provided to the
CollectionViewDriver
. -
didDeselect(with:
Default implementation) Tells the view model that its cell was deselected.
Implement this method to handle this event, optionally using the provided
coordinator
.Default Implementation
Default implementation. Calls
didDeselectCell(viewModel:)
on thecoordinator
, passingself
to theviewModel
parameter.Declaration
Swift
@MainActor func didDeselect(with coordinator: CellEventCoordinator?)
Parameters
coordinator
An event coordinator object, if one was provided to the
CollectionViewDriver
. -
willDisplay()
Default implementationTells the view model that its cell is about to be displayed in the collection view. This corresponds to the delegate method
collectionView(_:willDisplay:forItemAt:)
.Default Implementation
Default implementation. Does nothing.
Declaration
Swift
@MainActor func willDisplay()
-
didEndDisplaying()
Default implementationTells the view model that its cell was removed from the collection view. This corresponds to the delegate method
collectionView(_:didEndDisplaying:forItemAt:)
.Default Implementation
Default implementation. Does nothing.
Declaration
Swift
@MainActor func didEndDisplaying()
-
didHighlight()
Default implementationTells the view model that its cell was highlighted. This corresponds to the delegate method
collectionView(_:didHighlightItemAt:)
.Default Implementation
Default implementation. Does nothing.
Declaration
Swift
@MainActor func didHighlight()
-
didUnhighlight()
Default implementationTells the view model that the highlight was removed from its cell. This corresponds to the delegate method
collectionView(_:didUnhighlightItemAt:)
.Default Implementation
Default implementation. Does nothing.
Declaration
Swift
@MainActor func didUnhighlight()
-
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