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 d90369f

Browse files
initial work
1 parent 112f73b commit d90369f

File tree

4 files changed

+17
-17
lines changed

4 files changed

+17
-17
lines changed

‎Example/Sources/TableViewController.swift‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ final class TableViewController: UITableViewController {
5252

5353
// ** optional editing **
5454
// if needed, enable the editing functionality on the tableView
55-
let tableDataSourceEditingController = TableEditingController(
56-
canEditRow: { (tableView, indexPath) -> Bool in
55+
let tableDataSourceEditingController:TableEditingController<DataSource<Section<CellViewModel>>> = TableEditingController(
56+
canEditRow: { (tableView, indexPath, dataSource:inoutDataSource) -> Bool in
5757
return true
58-
},
59-
commitEditing:{[unowned self](tableView, editingStyle, indexPath) in
58+
},
59+
commitEditing:{(tableView, editingStyle, indexPath, dataSource:inoutDataSource) in
6060
if editingStyle == .delete {
61-
if let _ = self.dataSourceProvider?.dataSource.remove(at: indexPath) {
61+
if let _ = dataSource.remove(at: indexPath) {
6262
tableView.deleteRows(at: [indexPath], with: .automatic)
6363
}
6464
}

‎Source/DataSourceProvider.swift‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ where CellFactory.Item == DataSource.Item, SupplementaryFactory.Item == DataSour
3737
public let supplementaryFactory: SupplementaryFactory
3838

3939
fileprivate var bridgedDataSource: BridgedDataSource?
40-
fileprivate var _tableEditingController: TableEditingController?
40+
fileprivate var _tableEditingController: TableEditingController<DataSource>?
4141

4242
// MARK: Initialization
4343

@@ -73,7 +73,7 @@ public extension DataSourceProvider where CellFactory.View: UITableViewCell {
7373
return bridgedDataSource!
7474
}
7575

76-
public var tableEditingController: TableEditingController? {
76+
public var tableEditingController: TableEditingController<DataSource>? {
7777
set {
7878
_tableEditingController = newValue
7979
}
@@ -106,11 +106,11 @@ 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)
109+
return controller.canEditRow(tableView, indexPath,&self.dataSource)
110110
}
111111

112112
dataSource.tableCommitEditingStyleForRow = { [unowned self] (tableView, editingStyle, indexPath) in
113-
self.tableEditingController?.commitEditing(tableView, editingStyle, indexPath)
113+
self.tableEditingController?.commitEditing(tableView, editingStyle, indexPath,&self.dataSource)
114114
}
115115

116116
return dataSource

‎Source/TableEditingController.swift‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import UIKit
2222
/**
2323
An instance of `TableEditingController` allows editing a table view via inserting and deleting rows.
2424
*/
25-
public struct TableEditingController {
25+
public struct TableEditingController<DataSource:DataSourceProtocol> {
2626

2727
// MARK: Typealiases
2828

@@ -34,7 +34,7 @@ public struct TableEditingController {
3434

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

3939
/**
4040
Commits the editing actions for the specified index path.
@@ -43,14 +43,14 @@ public struct TableEditingController {
4343
- parameter commit: The editing style.
4444
- parameter indexPath: The index path of the item.
4545
*/
46-
public typealias CommitEditingConfig = (_ tableView: UITableView, _ commit: UITableViewCellEditingStyle, _ indexPath: IndexPath) -> Void
46+
public typealias CommitEditingConfig = (_ tableView: UITableView, _ commit: UITableViewCellEditingStyle, _ indexPath: IndexPath, _ dataSource:inoutDataSource) -> Void
4747

4848
/// A closure that determines if a given row is editable.
4949
public let canEditRow: CanEditRowConfig
5050

5151
/// A closure that commits the editing actions for a table view.
5252
public let commitEditing: CommitEditingConfig
53-
53+
5454
// MARK: Initialization
5555

5656
/**

‎Tests/DataSourceProviderTests.swift‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -399,13 +399,13 @@ final class DataSourceProviderTests: TestCase {
399399
}
400400

401401
// GIVEN: a data source editing controller
402-
let tableDataSourceEditingController = TableEditingController(
403-
canEditRow: { (tableView, indexPath) -> Bool in
402+
let tableDataSourceEditingController = TableEditingController<DataSource<Section<FakeViewModel>>>(
403+
canEditRow: { (tableView, indexPath, dataSource:inoutDataSource) -> Bool in
404404
return indexPath == expectedIndexPath
405405
},
406-
commitEditing:{ (tableView, editingStyle, indexPath) in
406+
commitEditing:{ (tableView, editingStyle, indexPath, dataSource:inoutDataSource) in
407407
if editingStyle == .delete {
408-
if let _ = dataSourceProvider.dataSource.remove(at: indexPath) {
408+
if let _ = dataSource.remove(at: indexPath) {
409409
tableView.deleteRows(at: [indexPath], with: .automatic)
410410
}
411411
}

0 commit comments

Comments
(0)

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