Skip to content

Commit 155c2d4

Browse files
committed
Documentation updates
1 parent b2c1a1f commit 155c2d4

File tree

1 file changed

+25
-26
lines changed

1 file changed

+25
-26
lines changed

Sources/FHDiffableViewControllers/FHDiffableTableViewController.swift

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import FHExtensions
66
/// A subclass of **UITableViewController** with diffable data source.
77
open class FHDiffableTableViewController<SectionIdentifierType, ItemIdentifierType>: UITableViewController where SectionIdentifierType: Hashable, ItemIdentifierType: Hashable {
88

9-
// MARK: - Public Classes
9+
// MARK: - Classes
1010

1111
/// A subclass of **UITableViewDiffableDataSource**, where the section title will be displayed if the snapshot contains more then one section.
1212
open class FHDataSource: UITableViewDiffableDataSource<SectionIdentifierType, ItemIdentifierType> {
@@ -22,16 +22,16 @@ open class FHDiffableTableViewController<SectionIdentifierType, ItemIdentifierTy
2222

2323
// MARK: - Typealias
2424

25-
/// A typealias for an **NSDiffableDataSourceSnapshot** type.
25+
/// A typealias for **NSDiffableDataSourceSnapshot** type.
2626
public typealias FHSnapshot = NSDiffableDataSourceSnapshot<SectionIdentifierType, ItemIdentifierType>
2727

28-
/// A typealias for an **FHDiffableDataSourceSnapshotSection** array type.
28+
/// A typealias for **FHDiffableDataSourceSnapshotSection** array type.
2929
public typealias FHSnapshotData = [FHDiffableDataSourceSnapshotSection<SectionIdentifierType, ItemIdentifierType>]
3030

3131

3232
// MARK: - Private Properties
3333

34-
private var _cellProvicer: ((UITableView, IndexPath, ItemIdentifierType) -> UITableViewCell?) = { (tableView, indexPath, itemIdentifier) in
34+
private var _cellProvicer: FHDataSource.CellProvider = { (tableView, indexPath, itemIdentifier) in
3535
let cell = tableView.dequeueReusableCell(withIdentifier: "default", for: indexPath)
3636
cell.textLabel?.text = "\(itemIdentifier)"
3737
return cell
@@ -42,31 +42,15 @@ open class FHDiffableTableViewController<SectionIdentifierType, ItemIdentifierTy
4242

4343
// MARK: - Public Properties
4444

45-
/// The data source for the table view.
46-
///
47-
/// Override this property only if you want to apply your custom **UITableViewDiffableDataSource**. For cell configuration overried the `cellProvider` property.
48-
///
49-
/// lazy var customDataSource = CustomDataSource(tableView: tableView, cellProvider: cellProvider)
50-
///
51-
/// override var dataSource: UITableViewDiffableDataSource<SectionIdentifierType, ItemIdentifierType> {
52-
/// return customDataSource
53-
/// }
54-
///
55-
/// - important: You need to use a lazy var for it to work properly!
56-
open var dataSource: UITableViewDiffableDataSource<SectionIdentifierType, ItemIdentifierType> {
57-
return _dataSource
58-
}
59-
6045
/// The cell provider which creates the cells.
6146
///
62-
/// Override this property to configure your custom cell the way you want.
47+
/// Override this property to configure a custom cell.
6348
///
64-
/// The default implementation just shows the description in the textLabel.
49+
/// The default implementation just shows the description in the `textLabel`.
6550
///
66-
/// override var cellProvider: ((UITableView, IndexPath, ItemIdentifierType) -> UITableViewCell?) {
51+
/// override var cellProvider: UITableViewDiffableDataSource<SectionIdentifierType, ItemIdentifierType>.CellProvider {
6752
/// return { (tableView, indexPath, itemIdentifier) in
6853
/// let cell = tableView.dequeueReusableCell(withIdentifier: /*your identifier*/, for: indexPath) as? CustomCell
69-
/// cell?.textLabel?.text = itemIdentifier.text
7054
/// /*customize your cell here*/
7155
/// return cell
7256
/// }
@@ -75,18 +59,33 @@ open class FHDiffableTableViewController<SectionIdentifierType, ItemIdentifierTy
7559
/// - important: Do not forget to register the reuseable cell before the first snapshot is applied!
7660
///
7761
/// tableView.register(CustomCell.self, forCellReuseIdentifier: /*your identifier*/) // e.g. in viewDidLoad()
78-
open var cellProvider: ((UITableView, IndexPath, ItemIdentifierType) -> UITableViewCell?) {
62+
open var cellProvider: UITableViewDiffableDataSource<SectionIdentifierType, ItemIdentifierType>.CellProvider {
7963
return _cellProvicer
8064
}
8165

66+
/// The data source for the table view.
67+
///
68+
/// Override this property only if a custom **UITableViewDiffableDataSource** should be applied. For cell configuration overried the `cellProvider` property.
69+
///
70+
/// lazy var customDataSource = CustomDataSource(tableView: tableView, cellProvider: cellProvider)
71+
///
72+
/// override var dataSource: UITableViewDiffableDataSource<SectionIdentifierType, ItemIdentifierType> {
73+
/// return customDataSource
74+
/// }
75+
///
76+
/// - important: You need to use a lazy var for it to work properly!
77+
open var dataSource: UITableViewDiffableDataSource<SectionIdentifierType, ItemIdentifierType> {
78+
return _dataSource
79+
}
80+
8281

8382
// MARK: - Public Methods
8483

8584
/// This method applys a new snapshot to the table view.
8685
///
8786
/// This is the equivalent for `reloadData()` or `performBatchUpdates(_:)`
8887
///
89-
/// With the `animatingDifferences`parameter you can disable the updating animation. If you want to have a different one you have to change this property:
88+
/// With the `animatingDifferences`parameter the update animation can be disabled. For a different animation this property needs to be modified:
9089
///
9190
/// dataSource.defaultRowAnimation = .automatic
9291
///
@@ -110,7 +109,7 @@ open class FHDiffableTableViewController<SectionIdentifierType, ItemIdentifierTy
110109
snapshotData.forEach { (section) in
111110
snapshot.appendItems(section.itemIdentifiers, toSection: section.sectionIdentifier)
112111
}
113-
dataSource.defaultRowAnimation = .automatic
112+
114113
dataSource.apply(snapshot, animatingDifferences: animatingDifferences, completion: completion)
115114
}
116115

0 commit comments

Comments
 (0)