Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d1e4552

Browse files
Merge branch 'TableEditingController_Improvement' into issue_80_refine_TableEditingController_design
# Conflicts: # Example/Sources/TableViewController.swift # Source/DataSourceProvider.swift # Source/TableEditingController.swift # Tests/DataSourceProviderTests.swift
2 parents d90369f + 5f7a372 commit d1e4552

File tree

4 files changed

+7
-5
lines changed

4 files changed

+7
-5
lines changed

‎Example/Sources/TableViewController.swift‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ final class TableViewController: UITableViewController {
5353
// ** optional editing **
5454
// if needed, enable the editing functionality on the tableView
5555
let tableDataSourceEditingController: TableEditingController<DataSource<Section<CellViewModel>>> = TableEditingController(
56-
canEditRow: { (tableView, indexPath, dataSource:inoutDataSource) -> Bool in
56+
canEditRow: { (item, tableView, indexPath) -> Bool in
5757
return true
5858
},
5959
commitEditing: { (tableView, editingStyle, indexPath, dataSource: inout DataSource) in

‎Source/DataSourceProvider.swift‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ public extension DataSourceProvider where CellFactory.View: UITableViewCell {
106106

107107
dataSource.tableCanEditRow = { [unowned self] (tableView, indexPath) -> Bool in
108108
guard let controller = self.tableEditingController else { return false }
109-
return controller.canEditRow(tableView, indexPath, &self.dataSource)
109+
let item = self.dataSource.item(atIndexPath: indexPath)!
110+
return controller.canEditRow(item, tableView, indexPath)
110111
}
111112

112113
dataSource.tableCommitEditingStyleForRow = { [unowned self] (tableView, editingStyle, indexPath) in

‎Source/TableEditingController.swift‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,18 @@ public struct TableEditingController<DataSource: DataSourceProtocol> {
2828

2929
/**
3030
Asks if a row at the specified index path is editable for the specified table view.
31-
31+
- parameter item: The item at `indexPath`.
3232
- parameter tableView: The table view requesting this information.
3333
- parameter indexPath: The index path of the item.
3434

3535
- returns: `true` if the specified row is editable, `false` otherwise.
3636
*/
37-
public typealias CanEditRowConfig = (_ tableView:UITableView, _ indexPath:IndexPath, _ dataSource:inoutDataSource) -> Bool
37+
public typealias CanEditRowConfig = (_ item:DataSource.Item?, _ tableView:UITableView, _ indexPath:IndexPath) -> Bool
3838

3939
/**
4040
Commits the editing actions for the specified index path.
4141

42+
- parameter item: The item at `indexPath`.
4243
- parameter tableView: The table view being edited.
4344
- parameter commit: The editing style.
4445
- parameter indexPath: The index path of the item.

‎Tests/DataSourceProviderTests.swift‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ final class DataSourceProviderTests: TestCase {
400400

401401
// GIVEN: a data source editing controller
402402
let tableDataSourceEditingController = TableEditingController<DataSource<Section<FakeViewModel>>>(
403-
canEditRow: { (tableView, indexPath, dataSource:inoutDataSource) -> Bool in
403+
canEditRow: { (item, tableView, indexPath) -> Bool in
404404
return indexPath == expectedIndexPath
405405
},
406406
commitEditing:{ (tableView, editingStyle, indexPath, dataSource: inout DataSource) in

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /