From 9cf825a919180e16183aa02bbe5c7a6721cc0c31 Mon Sep 17 00:00:00 2001 From: Christian Gossain Date: Tue, 22 Jan 2019 17:27:28 -0700 Subject: [PATCH 1/2] =?UTF-8?q?Pass=20=E2=80=98Row=E2=80=99=20model=20to?= =?UTF-8?q?=20selection=20handler?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Access to the the row data (including the context dictionnary) within this handler can be useful. --- Static/DataSource.swift | 4 ++-- Static/Row.swift | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Static/DataSource.swift b/Static/DataSource.swift index 4615319..f53a433 100644 --- a/Static/DataSource.swift +++ b/Static/DataSource.swift @@ -292,7 +292,7 @@ extension DataSource: UITableViewDelegate { } if let row = row(at: indexPath) { - row.selection?() + row.selection?(row) } tableViewDelegate?.tableView?(tableView, didSelectRowAt: indexPath) @@ -300,7 +300,7 @@ extension DataSource: UITableViewDelegate { public func tableView(_ tableView: UITableView, accessoryButtonTappedForRowWith indexPath: IndexPath) { if let row = row(at: indexPath) { - row.accessory.selection?() + row.accessory.selection?(row) } tableViewDelegate?.tableView?(tableView, accessoryButtonTappedForRowWith: indexPath) diff --git a/Static/Row.swift b/Static/Row.swift index 4909870..c11176b 100644 --- a/Static/Row.swift +++ b/Static/Row.swift @@ -1,7 +1,7 @@ import UIKit /// Row or Accessory selection callback. -public typealias Selection = () -> Void +public typealias Selection = (Row) -> Void public typealias ValueChange = (Bool) -> () public typealias SegmentedControlValueChange = (Int, Any?) -> () From b60dffd9e2fe54d81b990fae29683110984281a1 Mon Sep 17 00:00:00 2001 From: Christian Gossain Date: Fri, 25 Jan 2019 15:09:06 -0700 Subject: [PATCH 2/2] Update tests to reflect change with selection handler --- Static/Tests/DataSourceTests.swift | 6 +++--- Static/Tests/RowTests.swift | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Static/Tests/DataSourceTests.swift b/Static/Tests/DataSourceTests.swift index 67664f5..4772e26 100644 --- a/Static/Tests/DataSourceTests.swift +++ b/Static/Tests/DataSourceTests.swift @@ -92,14 +92,14 @@ class DataSourceTests: XCTestCase { XCTAssertFalse(dataSource.tableView(tableView, shouldHighlightRowAt: IndexPath(row: 0, section: 0))) dataSource.sections = [ - Section(rows: [Row(text: "Cupcakes", selection: {})]) + Section(rows: [Row(text: "Cupcakes", selection: { (row) in })]) ] XCTAssertTrue(dataSource.tableView(tableView, shouldHighlightRowAt: IndexPath(row: 0, section: 0))) } func testSelection() { let expectation = self.expectation(description: "Selected") - let selection = { + let selection: Selection = { (row) in expectation.fulfill() } @@ -112,7 +112,7 @@ class DataSourceTests: XCTestCase { func testAccessorySelection() { let expectation = self.expectation(description: "Accessory Selected") - let selection = { + let selection: Selection = { (row) in expectation.fulfill() } diff --git a/Static/Tests/RowTests.swift b/Static/Tests/RowTests.swift index 2cc9c7a..2979ed6 100644 --- a/Static/Tests/RowTests.swift +++ b/Static/Tests/RowTests.swift @@ -4,7 +4,7 @@ import Static class RowTests: XCTestCase { func testInit() { - let selection: Selection = {} + let selection: Selection = { (row) in } let context: Row.Context = [ "Hello": "world" ] @@ -36,7 +36,7 @@ class RowTests: XCTestCase { } func testInitWithSelectableAccessoryType() { - let selection: Selection = {} + let selection: Selection = { (row) in } let accessory: Row.Accessory = .detailButton(selection) let row = Row(accessory: accessory)