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
CollectionViewModelis 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
UICollectionViewwill 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 theautomaticDiffingEnabledproperty.If
automaticDiffingEnabledis set totrue, and cells/sections have been moved/inserted/deleted, updating this property will result in the UI of the collection view being updated automatically.If
automaticDiffingEnabledis set tofalse, and cells/sections have been moved/inserted/deleted, the caller must update theUICollectionViewstate manually, to bring it back in sync with the new model, e.g. by callingreloadData()on the collection view.Declaration
Swift
public var collectionViewModel: CollectionViewModel? { get set }
-
Initializes a data source that drives a
UICollectionViewbased on aCollectionViewModel.Declaration
Swift
public init( collectionView: UICollectionView, collectionViewModel: CollectionViewModel? = nil, shouldDeselectUponSelection: Bool = true, automaticDiffingEnabled: Bool = true)Parameters
collectionViewthe collection view to which this data source will render its view models.
collectionViewModelthe view model that describes the initial state of this collection view.
shouldDeselectUponSelectionindicates if selected cells should immediately be deselected. Defaults to
true.automaticDiffingEnableddefines 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
collectionViewModelproperty is updated.Declaration
Swift
public func refreshViews()
View on GitHub
CollectionViewDriver Class Reference