TableViewDiffableDataSource
open class TableViewDiffableDataSource<SectionIdentifierType, ItemIdentifierType> : NSObject, UITableViewDataSource where SectionIdentifierType : Hashable, ItemIdentifierType : Hashable
A class for backporting UITableViewDiffableDataSource
introduced in iOS 13.0+, tvOS 13.0+.
Represents the data model object for UITableView
that can be applies the
changes with automatic diffing.
-
The type of closure providing the cell.
Declaration
Swift
public typealias CellProvider = (UITableView, IndexPath, ItemIdentifierType) -> UITableViewCell?
-
The default animation to updating the views.
Declaration
Swift
public var defaultRowAnimation: UITableView.RowAnimation
-
Creates a new data source.
Declaration
Swift
public init(tableView: UITableView, cellProvider: @escaping CellProvider)
Parameters
tableView
A table view instance to be managed.
cellProvider
A closure to dequeue the cell for rows.
-
Applies given snapshot to perform automatic diffing update.
Declaration
Swift
public func apply(_ snapshot: DiffableDataSourceSnapshot<SectionIdentifierType, ItemIdentifierType>, animatingDifferences: Bool = true, completion: (() -> Void)? = nil)
Parameters
snapshot
A snapshot object to be applied to data model.
animatingDifferences
A Boolean value indicating whether to update with diffing animation.
completion
An 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
indexPath
An 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
itemIdentifier
An 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 tableView: UITableView) -> Int
Parameters
tableView
A table 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 tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
Parameters
tableView
A table view instance managed by
self
.section
An index of section.
Return Value
The number of items in the specified section.
-
Returns the title for the specified section’s header.
Declaration
Swift
open func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String?
Parameters
tableView
A table view instance managed by
self
.section
An index of section.
Return Value
The title for the specified section’s header, or
nil
for no title. -
Returns the title for the specified section’s footer.
Declaration
Swift
open func tableView(_ tableView: UITableView, titleForFooterInSection section: Int) -> String?
Parameters
tableView
A table view instance managed by
self
.section
An index of section.
Return Value
The title for the specified section’s footer, or
nil
for no title. -
Returns a cell for row at specified index path.
Declaration
Swift
open func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
Parameters
tableView
A table view instance managed by
self
.indexPath
An index path for cell.
Return Value
A cell for row at specified index path.
-
Returns whether it is possible to edit a row at given index path.
Declaration
Swift
open func tableView(_ tableView: UITableView, canEditRowAt: IndexPath) -> Bool
Parameters
tableView
A table view instance managed by
self
.section
An index of section.
Return Value
A boolean for row at specified index path.
-
Returns whether it is possible to move a row at given index path.
Declaration
Swift
open func tableView(_ tableView: UITableView, canMoveRowAt _: IndexPath) -> Bool
Parameters
tableView
A table view instance managed by
self
.section
An index of section.
Return Value
A boolean for row at specified index path.
-
Performs the edit action for a row at given index path.
Declaration
Swift
open func tableView(_ tableView: UITableView, commit _: UITableViewCell.EditingStyle, forRowAt _: IndexPath)
Parameters
tableView
A table view instance managed by
self
.editingStyle
An action for given edit action.
indexPath
An index path for cell.
Return Value
Void.
-
Moves a row at given index path.
Declaration
Swift
open func tableView(_ tableView: UITableView, moveRowAt _: IndexPath, to _: IndexPath)
Parameters
tableView
A table view instance managed by
self
.source
An index path for given cell position.
target
An index path for target cell position.
Return Value
Void.
-
Return list of section titles to display in section index view (e.g.
ABCD…Z#
).Declaration
Swift
open func sectionIndexTitles(for tableView: UITableView) -> [String]?
Parameters
tableView
A table view instance managed by
self
.Return Value
The list of section titles to display.
-
Tell table which section corresponds to section title/index (e.g.
B
,1)).Declaration
Swift
open func tableView(_ tableView: UITableView, sectionForSectionIndexTitle _: String, at section: Int) -> Int
Parameters
tableView
A table view instance managed by
self
.title
The title as displayed in the section index of tableView.
section
An index number identifying a section title in the array returned by sectionIndexTitles(for tableView:).
Return Value
The list of section titles to display.