diff --git a/Sources/ConfigurableCell.swift b/Sources/ConfigurableCell.swift index 021bad6..18035ff 100644 --- a/Sources/ConfigurableCell.swift +++ b/Sources/ConfigurableCell.swift @@ -20,35 +20,26 @@ import UIKit -public protocol ReusableCell { - - static func reusableIdentifier() -> String - static func nib() -> UINib? -} - -public protocol ConfigurableCell: ReusableCell { +public protocol ConfigurableCell { associatedtype T + static var reuseIdentifier: String { get } static var estimatedHeight: CGFloat? { get } static var defaultHeight: CGFloat? { get } func configure(with _: T) } -public extension ReusableCell where Self: UITableViewCell { - - static func reusableIdentifier() -> String { - return String(self) - } - - static func nib() -> UINib? { - return nil - } -} - public extension ConfigurableCell where Self: UITableViewCell { + static var reuseIdentifier: String { + get { + return String(self) + } + + } + static var estimatedHeight: CGFloat? { get { return UITableViewAutomaticDimension diff --git a/Sources/HeightStrategy.swift b/Sources/HeightStrategy.swift index 7723bdd..66eec6f 100644 --- a/Sources/HeightStrategy.swift +++ b/Sources/HeightStrategy.swift @@ -49,7 +49,7 @@ public class PrototypeHeightStrategy: CellHeightCalculatable { return height } - guard let cell = tableView.dequeueReusableCellWithIdentifier(row.reusableIdentifier) else { return 0 } + guard let cell = tableView.dequeueReusableCellWithIdentifier(row.reuseIdentifier) else { return 0 } cell.bounds = CGRectMake(0, 0, tableView.bounds.size.width, cell.bounds.height) diff --git a/Sources/TableCellManager.swift b/Sources/TableCellManager.swift index 5cc29e8..e4b8c9a 100644 --- a/Sources/TableCellManager.swift +++ b/Sources/TableCellManager.swift @@ -29,16 +29,16 @@ public class TableCellManager { self.tableView = tableView } - public func register(cellType cellType: AnyClass, forReusableCellIdentifier reusableIdentifier: String) { + public func register(cellType cellType: AnyClass, forCellReuseIdentifier reuseIdentifier: String) { - if registeredIds.contains(reusableIdentifier) { + if registeredIds.contains(reuseIdentifier) { return } // check if cell is already registered, probably cell has been registered by storyboard - if tableView?.dequeueReusableCellWithIdentifier(reusableIdentifier) != nil { + if tableView?.dequeueReusableCellWithIdentifier(reuseIdentifier) != nil { - registeredIds.insert(reusableIdentifier) + registeredIds.insert(reuseIdentifier) return } @@ -46,13 +46,13 @@ public class TableCellManager { // we hope that cell's xib file has name that equals to cell's class name // in that case we could register nib - if let _ = bundle.pathForResource(reusableIdentifier, ofType: "nib") { - tableView?.registerNib(UINib(nibName: reusableIdentifier, bundle: bundle), forCellReuseIdentifier: reusableIdentifier) + if let _ = bundle.pathForResource(reuseIdentifier, ofType: "nib") { + tableView?.registerNib(UINib(nibName: reuseIdentifier, bundle: bundle), forCellReuseIdentifier: reuseIdentifier) // otherwise, register cell class } else { - tableView?.registerClass(cellType, forCellReuseIdentifier: reusableIdentifier) + tableView?.registerClass(cellType, forCellReuseIdentifier: reuseIdentifier) } - registeredIds.insert(reusableIdentifier) + registeredIds.insert(reuseIdentifier) } } \ No newline at end of file diff --git a/Sources/TableDirector.swift b/Sources/TableDirector.swift index 6794b24..ff6fd3f 100644 --- a/Sources/TableDirector.swift +++ b/Sources/TableDirector.swift @@ -123,9 +123,9 @@ public class TableDirector: NSObject, UITableViewDataSource, UITableViewDelegate let row = sections[indexPath.section].items[indexPath.row] - cellManager?.register(cellType: row.cellType, forReusableCellIdentifier: row.reusableIdentifier) + cellManager?.register(cellType: row.cellType, forCellReuseIdentifier: row.reuseIdentifier) - let cell = tableView.dequeueReusableCellWithIdentifier(row.reusableIdentifier, forIndexPath: indexPath) + let cell = tableView.dequeueReusableCellWithIdentifier(row.reuseIdentifier, forIndexPath: indexPath) if cell.frame.size.width != tableView.frame.size.width { cell.frame = CGRectMake(0, 0, tableView.frame.size.width, cell.frame.size.height) diff --git a/Sources/TableRow.swift b/Sources/TableRow.swift index e0af219..b3cd9d1 100644 --- a/Sources/TableRow.swift +++ b/Sources/TableRow.swift @@ -38,7 +38,7 @@ public protocol RowHashable { public protocol Row: RowConfigurable, RowActionable, RowHashable { - var reusableIdentifier: String { get } + var reuseIdentifier: String { get } var cellType: AnyClass { get } var estimatedHeight: CGFloat? { get } @@ -54,8 +54,8 @@ public class TableRow String { + static var reuseIdentifier: String { return TestTableViewCellOptions.ReusableIdentifier }