CollectionViewDriver

@objc
public class CollectionViewDriver : NSObject

A data source that drives the collection views appereance and behavior based on an underlying CollectionViewModel.

  • The collection view to which the CollectionViewModel is rendered.

    Declaration

    Swift

    public let collectionView: UICollectionView
  • Describes the current UI state of the collection view.

    When this property is set, the UI of the related UICollectionView will be updated. If not only the content of individual cells/sections has changed, but instead cells/sections were moved/inserted/deleted, the behavior of this setter depends on the value of the automaticDiffingEnabled property.

    If automaticDiffingEnabled is set to true, and cells/sections have been moved/inserted/deleted, updating this property will result in the UI of the collection view being updated automatically.

    If automaticDiffingEnabled is set to false, and cells/sections have been moved/inserted/deleted, the caller must update the UICollectionView state manually, to bring it back in sync with the new model, e.g. by calling reloadData() on the collection view.

    Declaration

    Swift

    public var collectionViewModel: CollectionViewModel? { get set }
  • Initializes a data source that drives a UICollectionView based on a CollectionViewModel.

    Declaration

    Swift

    public init(
        collectionView: UICollectionView,
        collectionViewModel: CollectionViewModel? = nil,
        shouldDeselectUponSelection: Bool = true,
        automaticDiffingEnabled: Bool = true)

    Parameters

    collectionView

    the collection view to which this data source will render its view models.

    collectionViewModel

    the view model that describes the initial state of this collection view.

    shouldDeselectUponSelection

    indicates if selected cells should immediately be deselected. Defaults to true.

    automaticDiffingEnabled

    defines whether or not this data source updates the collection view automatically when cells/sections are moved/inserted/deleted. Defaults to false.

  • Updates all currently visible cells and sections, such that they reflect the latest state decribed in their respective view models. Typically this method should not be called directly, as it is called automatically whenever the collectionViewModel property is updated.

    Declaration

    Swift

    public func refreshViews()