CollectionViewDiffableDataSource
open class CollectionViewDiffableDataSource<SectionIdentifierType, ItemIdentifierType> : NSObject, UICollectionViewDataSource where SectionIdentifierType : Hashable, ItemIdentifierType : Hashable
A class for backporting UICollectionViewDiffableDataSource introduced in iOS 13.0+, tvOS 13.0+.
Represents the data model object for UICollectionView that can be applies the
changes with automatic diffing.
-
The type of closure providing the cell.
Declaration
Swift
public typealias CellProvider = (UICollectionView, IndexPath, ItemIdentifierType) -> UICollectionViewCell? -
The type of closure providing the supplementary view for element of kind.
Declaration
Swift
public typealias SupplementaryViewProvider = (UICollectionView, String, IndexPath) -> UICollectionReusableView? -
A closure to dequeue the views for element of kind.
Declaration
Swift
public var supplementaryViewProvider: SupplementaryViewProvider? -
Creates a new data source.
Declaration
Swift
public init(collectionView: UICollectionView, cellProvider: @escaping CellProvider)Parameters
collectionViewA collection view instance to be managed.
cellProviderA closure to dequeue the cell for items.
-
Applies given snapshot to perform automatic diffing update.
Declaration
Swift
public func apply(_ snapshot: DiffableDataSourceSnapshot<SectionIdentifierType, ItemIdentifierType>, animatingDifferences: Bool = true, completion: (() -> Void)? = nil)Parameters
snapshotA snapshot object to be applied to data model.
animatingDifferencesA Boolean value indicating whether to update with diffing animation.
completionAn optional completion block which is called when the complete performing updates.
-
Returns a new snapshot object of current state.
Declaration
Swift
public func snapshot() -> DiffableDataSourceSnapshot<SectionIdentifierType, ItemIdentifierType>Return Value
A new snapshot object of current state.
-
Returns an item identifier for given index path.
Declaration
Swift
public func itemIdentifier(for indexPath: IndexPath) -> ItemIdentifierType?Parameters
indexPathAn index path for the item identifier.
Return Value
An item identifier for given index path.
-
Returns an index path for given item identifier.
Declaration
Swift
public func indexPath(for itemIdentifier: ItemIdentifierType) -> IndexPath?Parameters
itemIdentifierAn identifier of item.
Return Value
An index path for given item identifier.
-
Returns the number of sections in the data source.
Declaration
Swift
public func numberOfSections(in collectionView: UICollectionView) -> IntParameters
collectionViewA collection view instance managed by
self.Return Value
The number of sections in the data source.
-
Returns the number of items in the specified section.
Declaration
Swift
public func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> IntParameters
collectionViewA collection view instance managed by
self.sectionAn index of section.
Return Value
The number of items in the specified section.
-
Returns a cell for item at specified index path.
Declaration
Swift
open func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCellParameters
collectionViewA collection view instance managed by
self.indexPathAn index path for cell.
Return Value
A cell for row at specified index path.
-
Returns a supplementary view for element of kind at specified index path.
Declaration
Swift
open func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableViewParameters
collectionViewA collection view instance managed by
self.kindThe kind of element to be display.
indexPathAn index path for supplementary view.
Return Value
A supplementary view for element of kind at specified index path.
-
Returns whether it is possible to edit a row at given index path.
Declaration
Swift
open func collectionView(_ collectionView: UICollectionView, canMoveItemAt indexPath: IndexPath) -> BoolParameters
collectionViewA collection view instance managed by
self.sectionAn index of section.
Return Value
A boolean for row at specified index path.
-
Moves a row at given index path.
Declaration
Swift
public func collectionView(_ collectionView: UICollectionView, moveItemAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath)Parameters
collectionViewA collection view instance managed by
self.sourceIndexPathAn index path for given cell position.
destinationIndexPathAn index path for target cell position.
Return Value
Void.
View on GitHub
CollectionViewDiffableDataSource Class Reference