@@ -31,14 +31,16 @@ import UIKit
3131open class SPDiffableTableDataSource : UITableViewDiffableDataSource < SPDiffableSection , SPDiffableItem > {
3232
3333 /**
34- Mediator call some methods which can not using in data source object.
34+ SPDiffable: Mediator call some methods which can not using in data source object.
3535
3636 Need set mediator for data source and implement methods which need.
3737 It allow manage for example header titles not ovveride data source class.
3838 Now data source doing only cell provider logic.
3939 */
4040 public weak var mediator : SPDiffableTableMediator ?
4141
42+ private weak var tableView : UITableView ?
43+
4244 public init ( tableView: UITableView , cellProviders: [ CellProvider ] ) {
4345 super. init ( tableView: tableView, cellProvider: { ( tableView, indexPath, item) -> UITableViewCell ? in
4446 for provider in cellProviders {
@@ -48,12 +50,13 @@ open class SPDiffableTableDataSource: UITableViewDiffableDataSource<SPDiffableSe
4850 }
4951 return nil
5052 } )
53+ self . tableView = tableView
5154 }
5255
53- // MARK: Apply Wrappers
56+ // MARK: - Apply Content
5457
5558 /**
56- Applying sections to current snapshot.
59+ SPDiffable: Applying sections to current snapshot.
5760
5861 Section convert to snapshot and appling after.
5962
@@ -70,7 +73,7 @@ open class SPDiffableTableDataSource: UITableViewDiffableDataSource<SPDiffableSe
7073 }
7174
7275 /**
73- Applying new snapshot insted of current.
76+ SPDiffable: Applying new snapshot insted of current.
7477
7578 - parameter snapshot: New snapshot.
7679 - parameter animating: Shoud apply changes with animation or not.
@@ -79,11 +82,25 @@ open class SPDiffableTableDataSource: UITableViewDiffableDataSource<SPDiffableSe
7982 apply ( snapshot, animatingDifferences: animated, completion: nil )
8083 }
8184
85+ // MARK: - Get Content
86+
87+ /**
88+ SPDiffable: Get indexPath for item by indetifier.
89+ */
8290 public func indexPath( for itemIdentifier: String ) -> IndexPath ? {
8391 return indexPath ( for: SPDiffableItem ( identifier: itemIdentifier) )
8492 }
8593
86- // MARK: Mediator
94+ /**
95+ SPDiffable: Get cell specific type `T` by indetifier.
96+ */
97+ public func cell< T: UITableViewCell > ( _ type: T . Type , for itemIdentifier: String ) -> T ? {
98+ guard let indexPath = indexPath ( for: itemIdentifier) else { return nil }
99+ guard let cell = self . tableView? . cellForRow ( at: indexPath) as? T else { return nil }
100+ return cell
101+ }
102+
103+ // MARK: - Mediator
87104
88105 public override func tableView( _ tableView: UITableView , titleForHeaderInSection section: Int ) -> String ? {
89106 if let title = mediator? . diffableTableView ? ( tableView, titleForHeaderInSection: section) {
0 commit comments