From fadb2f4e609977aa9f17f927ff826ca0e068ff22 Mon Sep 17 00:00:00 2001 From: Max Sokolov Date: Tue, 14 Jun 2016 23:50:30 +0300 Subject: [PATCH] add RowHashable protocol --- .../Presentation/Controllers/MainController.swift | 4 +--- Sources/HeightStrategy.swift | 2 +- Sources/TableRow.swift | 11 ++++++++++- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/Demo/Classes/Presentation/Controllers/MainController.swift b/Demo/Classes/Presentation/Controllers/MainController.swift index bec8ab6..91b855d 100644 --- a/Demo/Classes/Presentation/Controllers/MainController.swift +++ b/Demo/Classes/Presentation/Controllers/MainController.swift @@ -35,9 +35,7 @@ class MainController: UIViewController { let row1 = TableRow(item: "1") let row2 = TableRow(item: "2") let row3 = TableRow(item: "3", actions: [a]) - - - + row1 .addAction(TableRowAction(.shouldHighlight) { (data) -> Bool in diff --git a/Sources/HeightStrategy.swift b/Sources/HeightStrategy.swift index 9072767..72eef2e 100644 --- a/Sources/HeightStrategy.swift +++ b/Sources/HeightStrategy.swift @@ -27,7 +27,7 @@ public protocol HeightCalculatingStrategy { func height(indexPath: NSIndexPath, reusableIdentifier: String, configure: (cell: UITableViewCell) -> Void) -> CGFloat } -public class PrototypeHeightStrategy { +public class PrototypeHeightStrategy: HeightCalculatingStrategy { public weak var tableView: UITableView? private var cachedHeights = [Int: CGFloat]() diff --git a/Sources/TableRow.swift b/Sources/TableRow.swift index 62fd90b..e4b3fbb 100644 --- a/Sources/TableRow.swift +++ b/Sources/TableRow.swift @@ -31,7 +31,12 @@ public protocol RowActionable { func hasAction(action: TableRowActionType) -> Bool } -public protocol Row: RowConfigurable, RowActionable { +public protocol RowHashable { + + var hashValue: Int { get } +} + +public protocol Row: RowConfigurable, RowActionable, RowHashable { var reusableIdentifier: String { get } var estimatedHeight: CGFloat { get } @@ -42,6 +47,10 @@ public class TableRow]() + + public var hashValue: Int { + return ObjectIdentifier(self).hashValue + } public var reusableIdentifier: String { return CellType.reusableIdentifier()