diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..2b60b00 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,27 @@ +# Change Log + +All notable changes to this project will be documented in this file. + +## [2.0.0](https://github.com/maxsokolov/TableKit/releases/tag/1.4.0) +Released on 2016-09-06. Breaking changes in 2.0.0: +
The signatures of `TableRow` and `TableRowAction` classes were changed from +```swift +let action = TableRowAction(.click) { (data) in +} + +let row = TableRow(item: "some string", actions: [action]) +``` +to +```swift +let action = TableRowAction(.click) { (data) in +} + +let row = TableRow(item: "some string", actions: [action]) +``` +This is the great improvement that comes from the community. Thanks a lot! + +## [1.3.0](https://github.com/maxsokolov/TableKit/releases/tag/1.3.0) +Released on 2016-09-04. Swift 3.0 support. + +## [0.1.0](https://github.com/maxsokolov/TableKit/releases/tag/0.1.0) +Released on 2015-11-15. Initial release called Tablet. \ No newline at end of file diff --git a/Demo/Classes/Presentation/Controllers/AutolayoutCellsController.swift b/Demo/Classes/Presentation/Controllers/AutolayoutCellsController.swift index 9340070..9d9d3ad 100644 --- a/Demo/Classes/Presentation/Controllers/AutolayoutCellsController.swift +++ b/Demo/Classes/Presentation/Controllers/AutolayoutCellsController.swift @@ -30,10 +30,10 @@ class AutolayoutCellsController: UIViewController { while rows <= 1000 { rows += 1 - let row = TableRow(item: ()) + let row = TableRow(item: ()) section += row } tableDirector += section } -} \ No newline at end of file +} diff --git a/Demo/Classes/Presentation/Controllers/MainController.swift b/Demo/Classes/Presentation/Controllers/MainController.swift index dfb92c7..7c0afdd 100644 --- a/Demo/Classes/Presentation/Controllers/MainController.swift +++ b/Demo/Classes/Presentation/Controllers/MainController.swift @@ -23,7 +23,7 @@ class MainController: UIViewController { title = "TableKit" - let clickAction = TableRowAction(.click) { [weak self] (data) in + let clickAction = TableRowAction(.click) { [weak self] (data) in switch (data.indexPath as NSIndexPath).row { case 0: @@ -37,8 +37,8 @@ class MainController: UIViewController { let rows = [ - TableRow(item: "Autolayout cells", actions: [clickAction]), - TableRow(item: "Nib cells", actions: [clickAction]) + TableRow(item: "Autolayout cells", actions: [clickAction]), + TableRow(item: "Nib cells", actions: [clickAction]) ] // automatically creates a section, also could be used like tableDirector.append(rows: rows) diff --git a/Demo/Classes/Presentation/Controllers/NibCellsController.swift b/Demo/Classes/Presentation/Controllers/NibCellsController.swift index 082af9c..32736a6 100644 --- a/Demo/Classes/Presentation/Controllers/NibCellsController.swift +++ b/Demo/Classes/Presentation/Controllers/NibCellsController.swift @@ -22,11 +22,11 @@ class NibCellsController: UITableViewController { let numbers = [1000, 2000, 3000, 4000, 5000] - let shouldHighlightAction = TableRowAction(.shouldHighlight) { (_) -> Bool in + let shouldHighlightAction = TableRowAction(.shouldHighlight) { (_) -> Bool in return false } - let rows: [Row] = numbers.map { TableRow(item: $0, actions: [shouldHighlightAction]) } + let rows = numbers.map { TableRow(item: $0, actions: [shouldHighlightAction]) } tableDirector.append(rows: rows) } diff --git a/README.md b/README.md index af32809..dfad30d 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ Build Status Swift 3.0 compatible Carthage compatible - CocoaPods compatible + CocoaPods compatible Platform iOS License: MIT

@@ -36,9 +36,9 @@ Create your rows: ```swift import TableKit -let row1 = TableRow(item: "1") -let row2 = TableRow(item: 2) -let row3 = TableRow(item: User(name: "John Doe", rating: 5)) +let row1 = TableRow(item: "1") +let row2 = TableRow(item: 2) +let row3 = TableRow(item: User(name: "John Doe", rating: 5)) ``` Put rows into section: ```swift @@ -84,20 +84,20 @@ You could have as many rows and sections as you need. It nice to have some actions that related to your cells: ```swift -let action = TableRowAction(.click) { (data) in +let action = TableRowAction(.click) { (data) in // you could access any useful information that relates to the action // data.cell - StringTableViewCell? // data.item - String - // data.indexPath - NSIndexPath + // data.indexPath - IndexPath } -let row = TableRow(item: "some", actions: [action]) +let row = TableRow(item: "some", actions: [action]) ``` Or, using nice chaining approach: ```swift -let row = TableRow(item: "some") +let row = TableRow(item: "some") .action(.click) { (data) in } @@ -126,7 +126,7 @@ class MyTableViewCell: UITableViewCell, ConfigurableCell { ``` And handle them accordingly: ```swift -let myAction = TableRowAction(.custom(MyActions.ButtonClicked)) { (data) in +let myAction = TableRowAction(.custom(MyActions.ButtonClicked)) { (data) in } ``` @@ -173,11 +173,11 @@ It's never been so easy to deal with table views. ```swift let users = /* some users array */ -let click = TableRowAction(.click) { +let click = TableRowAction(.click) { } -let rows = users.filter({ $0.state == .active }).map({ TableRow(item: $0.name, actions: [click]) }) +let rows = users.filter({ $0.state == .active }).map({ TableRow(item: $0.name, actions: [click]) }) tableDirector += rows ``` @@ -215,6 +215,10 @@ Clone the repo and drag files from `Sources` folder into your Xcode project. - iOS 8.0 - Xcode 8.0 +# Changelog + +Keep eye on [changes](CHANGELOG.md). + # License TableKit is available under the MIT license. See LICENSE for details. \ No newline at end of file diff --git a/Sources/TableRow.swift b/Sources/TableRow.swift index bc40ec3..6cf3738 100644 --- a/Sources/TableRow.swift +++ b/Sources/TableRow.swift @@ -48,10 +48,10 @@ public protocol Row: RowConfigurable, RowActionable, RowHashable { var defaultHeight: CGFloat? { get } } -open class TableRow: Row where CellType.T == ItemType, CellType: UITableViewCell { +open class TableRow: Row where CellType: UITableViewCell { - open let item: ItemType - private lazy var actions = [String: TableRowAction]() + open let item: CellType.T + private lazy var actions = [String: TableRowAction]() private(set) open var editingActions: [UITableViewRowAction]? open var hashValue: Int { @@ -74,7 +74,7 @@ open class TableRow: Row where CellType.T return CellType.self } - public init(item: ItemType, actions: [TableRowAction]? = nil, editingActions: [UITableViewRowAction]? = nil) { + public init(item: CellType.T, actions: [TableRowAction]? = nil, editingActions: [UITableViewRowAction]? = nil) { self.item = item self.editingActions = editingActions @@ -108,16 +108,16 @@ open class TableRow: Row where CellType.T // MARK: - actions - @discardableResult - open func action(_ action: TableRowAction) -> Self { + open func action(_ action: TableRowAction) -> Self { actions[action.type.key] = action return self } @discardableResult - open func action(_ type: TableRowActionType, handler: @escaping (_ data: TableRowActionData) -> T) -> Self { + open func action(_ type: TableRowActionType, handler: @escaping (_ data: TableRowActionData) -> T) -> Self { - actions[type.key] = TableRowAction(type, handler: handler) + actions[type.key] = TableRowAction(type, handler: handler) return self } } diff --git a/Sources/TableRowAction.swift b/Sources/TableRowAction.swift index dac4b49..2533b6a 100644 --- a/Sources/TableRowAction.swift +++ b/Sources/TableRowAction.swift @@ -45,14 +45,14 @@ public enum TableRowActionType { } } -open class TableRowActionData where CellType.T == ItemType, CellType: UITableViewCell { +open class TableRowActionData where CellType: UITableViewCell { - open let item: ItemType + open let item: CellType.T open let cell: CellType? open let indexPath: IndexPath open let userInfo: [AnyHashable: Any]? - init(item: ItemType, cell: CellType?, path: IndexPath, userInfo: [AnyHashable: Any]?) { + init(item: CellType.T, cell: CellType?, path: IndexPath, userInfo: [AnyHashable: Any]?) { self.item = item self.cell = cell @@ -61,12 +61,12 @@ open class TableRowActionData where CellTy } } -private enum TableRowActionHandler where CellType.T == ItemType, CellType: UITableViewCell { +private enum TableRowActionHandler where CellType: UITableViewCell { - case voidAction((TableRowActionData) -> Void) - case action((TableRowActionData) -> Any?) + case voidAction((TableRowActionData) -> Void) + case action((TableRowActionData) -> Any?) - func invoke(item: ItemType, cell: UITableViewCell?, path: IndexPath) -> Any? { + func invoke(item: CellType.T, cell: UITableViewCell?, path: IndexPath) -> Any? { switch self { case .voidAction(let handler): @@ -77,24 +77,24 @@ private enum TableRowActionHandler where C } } -open class TableRowAction where CellType.T == ItemType, CellType: UITableViewCell { +open class TableRowAction where CellType: UITableViewCell { open let type: TableRowActionType - private let handler: TableRowActionHandler + private let handler: TableRowActionHandler - public init(_ type: TableRowActionType, handler: @escaping (_ data: TableRowActionData) -> Void) { + public init(_ type: TableRowActionType, handler: @escaping (_ data: TableRowActionData) -> Void) { self.type = type self.handler = .voidAction(handler) } - public init(_ type: TableRowActionType, handler: @escaping (_ data: TableRowActionData) -> T) { + public init(_ type: TableRowActionType, handler: @escaping (_ data: TableRowActionData) -> T) { self.type = type self.handler = .action(handler) } - func invoke(item: ItemType, cell: UITableViewCell?, path: IndexPath) -> Any? { + func invoke(item: CellType.T, cell: UITableViewCell?, path: IndexPath) -> Any? { return handler.invoke(item: item, cell: cell, path: path) } } diff --git a/TableKit.podspec b/TableKit.podspec index 30cbdea..1af280b 100644 --- a/TableKit.podspec +++ b/TableKit.podspec @@ -2,7 +2,7 @@ Pod::Spec.new do |s| s.name = 'TableKit' s.module_name = 'TableKit' - s.version = '1.3.1' + s.version = '2.0.0' s.homepage = 'https://github.com/maxsokolov/TableKit' s.summary = 'Type-safe declarative table views with Swift.' diff --git a/Tests/TableKitTests.swift b/Tests/TableKitTests.swift index a2cded4..014cf4d 100644 --- a/Tests/TableKitTests.swift +++ b/Tests/TableKitTests.swift @@ -94,7 +94,7 @@ class TabletTests: XCTestCase { let data = TestData(title: "title") - let row = TableRow(item: data) + let row = TableRow(item: data) testController.tableDirector += row testController.tableView.reloadData() @@ -111,7 +111,7 @@ class TabletTests: XCTestCase { let data = [TestData(title: "1"), TestData(title: "2"), TestData(title: "3")] - let rows: [Row] = data.map({ TableRow(item: $0) }) + let rows: [Row] = data.map({ TableRow(item: $0) }) testController.tableDirector += rows testController.tableView.reloadData() @@ -129,7 +129,7 @@ class TabletTests: XCTestCase { func testTableSectionCreatesSectionWithHeaderAndFooterTitles() { - let row = TableRow(item: TestData(title: "title")) + let row = TableRow(item: TestData(title: "title")) let sectionHeaderTitle = "Header Title" let sectionFooterTitle = "Footer Title" @@ -148,7 +148,7 @@ class TabletTests: XCTestCase { func testTableSectionCreatesSectionWithHeaderAndFooterViews() { - let row = TableRow(item: TestData(title: "title")) + let row = TableRow(item: TestData(title: "title")) let sectionHeaderView = UIView() let sectionFooterView = UIView() @@ -170,7 +170,7 @@ class TabletTests: XCTestCase { let expectation = self.expectation(description: "cell action") - let row = TableRow(item: TestData(title: "title")) + let row = TableRow(item: TestData(title: "title")) .action(TableRowAction(.custom(TestTableViewCellOptions.CellAction)) { (data) in XCTAssertNotNil(data.cell, "Action data should have a cell")