diff --git a/.swift-version b/.swift-version index 389f774..8012ebb 100644 --- a/.swift-version +++ b/.swift-version @@ -1 +1 @@ -4.0 \ No newline at end of file +4.2 \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 09c53af..228c26b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,5 @@ language: objective-c -osx_image: xcode9 +osx_image: xcode10 branches: only: - master @@ -7,7 +7,7 @@ env: global: - LC_CTYPE=en_US.UTF-8 - LANG=en_US.UTF-8 - - IOS_SDK=iphonesimulator11.0 + - IOS_SDK=iphonesimulator12.0 - SCHEME_IOS="TableKit" - PROJECT_FRAMEWORK="TableKit.xcodeproj" @@ -17,7 +17,7 @@ env: - DESTINATION="OS=9.2,name=iPhone 6S" SCHEME="$SCHEME_IOS" SDK="$IOS_SDK" - DESTINATION="OS=9.3,name=iPhone 6S Plus" SCHEME="$SCHEME_IOS" SDK="$IOS_SDK" - DESTINATION="OS=10.0,name=iPhone 5" SCHEME="$SCHEME_IOS" SDK="$IOS_SDK" - - DESTINATION="OS=10.0,name=iPhone 7 Plus" SCHEME="$SCHEME_IOS" SDK="$IOS_SDK" + - DESTINATION="OS=12.0,name=iPhone 7 Plus" SCHEME="$SCHEME_IOS" SDK="$IOS_SDK" script: - set -o pipefail diff --git a/CHANGELOG.md b/CHANGELOG.md index ad1533a..ebb1a04 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to this project will be documented in this file. +## [2.8.0](https://github.com/maxsokolov/TableKit/releases/tag/2.8.0) +Released on 2018-09-30. +- Swift 4.2 support. + ## [2.5.0](https://github.com/maxsokolov/TableKit/releases/tag/2.5.0) Released on 2017-09-24. - Swift 4.0 support. diff --git a/Demo/Classes/Presentation/Controllers/AutolayoutCellsController.swift b/Demo/Classes/Presentation/Controllers/AutolayoutCellsController.swift index 73c99ca..2ce3741 100644 --- a/Demo/Classes/Presentation/Controllers/AutolayoutCellsController.swift +++ b/Demo/Classes/Presentation/Controllers/AutolayoutCellsController.swift @@ -65,6 +65,6 @@ class AutolayoutCellsController: UIViewController { view.setNeedsLayout() view.layoutIfNeeded() - return view.systemLayoutSizeFitting(UILayoutFittingCompressedSize).height + return view.systemLayoutSizeFitting(UIView.layoutFittingCompressedSize).height } } diff --git a/Demo/TableKitDemo.xcodeproj/project.pbxproj b/Demo/TableKitDemo.xcodeproj/project.pbxproj index 21f4909..17885b9 100644 --- a/Demo/TableKitDemo.xcodeproj/project.pbxproj +++ b/Demo/TableKitDemo.xcodeproj/project.pbxproj @@ -233,13 +233,13 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0720; - LastUpgradeCheck = 0900; + LastUpgradeCheck = 1000; ORGANIZATIONNAME = Tablet; TargetAttributes = { DAB7EB261BEF787300D2AD5E = { CreatedOnToolsVersion = 7.0.1; DevelopmentTeam = Z48R734SJX; - LastSwiftMigration = 0800; + LastSwiftMigration = 1000; }; }; }; @@ -338,12 +338,14 @@ CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; @@ -391,12 +393,14 @@ CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; @@ -439,7 +443,7 @@ PRODUCT_BUNDLE_IDENTIFIER = com.tablekit.demo; PRODUCT_NAME = TableKitDemo; PROVISIONING_PROFILE = ""; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; }; name = Debug; }; @@ -456,7 +460,7 @@ PRODUCT_BUNDLE_IDENTIFIER = com.tablekit.demo; PRODUCT_NAME = TableKitDemo; PROVISIONING_PROFILE = ""; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; }; name = Release; }; diff --git a/Demo/TableKitDemo.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/Demo/TableKitDemo.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/Demo/TableKitDemo.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/README.md b/README.md index 4e10a91..c13a629 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,9 @@

Build Status - Swift 4.0 compatible + Swift 4.2 compatible Carthage compatible - CocoaPods compatible + CocoaPods compatible Platform iOS License: MIT

@@ -237,7 +237,7 @@ Clone the repo and drag files from `Sources` folder into your Xcode project. # Changelog -Keep eye on [changes](CHANGELOG.md). +Keep an eye on [changes](CHANGELOG.md). # License diff --git a/Sources/ConfigurableCell.swift b/Sources/ConfigurableCell.swift index dfb0ce1..48748b5 100644 --- a/Sources/ConfigurableCell.swift +++ b/Sources/ConfigurableCell.swift @@ -22,14 +22,14 @@ import UIKit public protocol ConfigurableCell { - associatedtype T + associatedtype CellData static var reuseIdentifier: String { get } static var estimatedHeight: CGFloat? { get } static var defaultHeight: CGFloat? { get } - func configure(with _: T) - func height(for _: T) -> CGFloat + func configure(with _: CellData) + func height(for _: CellData) -> CGFloat } diff --git a/Sources/TableCellAction.swift b/Sources/TableCellAction.swift index b962dab..b3ea0ba 100644 --- a/Sources/TableCellAction.swift +++ b/Sources/TableCellAction.swift @@ -27,13 +27,13 @@ import UIKit open class TableCellAction { /// The cell that triggers an action. - open let cell: UITableViewCell + public let cell: UITableViewCell /// The action unique key. - open let key: String + public let key: String /// The custom user info. - open let userInfo: [AnyHashable: Any]? + public let userInfo: [AnyHashable: Any]? public init(key: String, sender: UITableViewCell, userInfo: [AnyHashable: Any]? = nil) { diff --git a/Sources/TableDirector.swift b/Sources/TableDirector.swift index 548eafb..c17ce2c 100644 --- a/Sources/TableDirector.swift +++ b/Sources/TableDirector.swift @@ -147,7 +147,7 @@ open class TableDirector: NSObject, UITableViewDataSource, UITableViewDelegate { return row.defaultHeight ?? row.estimatedHeight ?? rowHeightCalculator?.estimatedHeight(forRow: row, at: indexPath) - ?? UITableViewAutomaticDimension + ?? UITableView.automaticDimension } open func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { @@ -163,7 +163,7 @@ open class TableDirector: NSObject, UITableViewDataSource, UITableViewDelegate { return rowHeight ?? row.defaultHeight ?? rowHeightCalculator?.height(forRow: row, at: indexPath) - ?? UITableViewAutomaticDimension + ?? UITableView.automaticDimension } // MARK: UITableViewDataSource - configuration @@ -215,7 +215,7 @@ open class TableDirector: NSObject, UITableViewDataSource, UITableViewDelegate { open func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat { let section = sections[section] - return section.headerHeight ?? section.headerView?.frame.size.height ?? UITableViewAutomaticDimension + return section.headerHeight ?? section.headerView?.frame.size.height ?? UITableView.automaticDimension } open func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat { @@ -223,7 +223,7 @@ open class TableDirector: NSObject, UITableViewDataSource, UITableViewDelegate { let section = sections[section] return section.footerHeight ?? section.footerView?.frame.size.height - ?? UITableViewAutomaticDimension + ?? UITableView.automaticDimension } // MARK: UITableViewDataSource - Index @@ -257,7 +257,6 @@ open class TableDirector: NSObject, UITableViewDataSource, UITableViewDelegate { // MARK: UITableViewDelegate - actions open func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { - let cell = tableView.cellForRow(at: indexPath) if invoke(action: .click, cell: cell, indexPath: indexPath) != nil { @@ -284,10 +283,10 @@ open class TableDirector: NSObject, UITableViewDataSource, UITableViewDelegate { } open func tableView(_ tableView: UITableView, willSelectRowAt indexPath: IndexPath) -> IndexPath? { - if hasAction(.willSelect, atIndexPath: indexPath) { return invoke(action: .willSelect, cell: tableView.cellForRow(at: indexPath), indexPath: indexPath) as? IndexPath } + return indexPath } @@ -300,15 +299,30 @@ open class TableDirector: NSObject, UITableViewDataSource, UITableViewDelegate { return sections[indexPath.section].rows[indexPath.row].editingActions } - open func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) { + open func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCell.EditingStyle { + if invoke(action: .canDelete, cell: tableView.cellForRow(at: indexPath), indexPath: indexPath) as? Bool ?? false { + return UITableViewCell.EditingStyle.delete + } + return UITableViewCell.EditingStyle.none + } + + public func tableView(_ tableView: UITableView, shouldIndentWhileEditingRowAt indexPath: IndexPath) -> Bool { + return false + } + + public func tableView(_ tableView: UITableView, targetIndexPathForMoveFromRowAt sourceIndexPath: IndexPath, toProposedIndexPath proposedDestinationIndexPath: IndexPath) -> IndexPath { + return invoke(action: .canMoveTo, cell: tableView.cellForRow(at: sourceIndexPath), indexPath: sourceIndexPath, userInfo: [TableKitUserInfoKeys.CellCanMoveProposedIndexPath: proposedDestinationIndexPath]) as? IndexPath ?? proposedDestinationIndexPath + } + + open func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) { if editingStyle == .delete { invoke(action: .clickDelete, cell: tableView.cellForRow(at: indexPath), indexPath: indexPath) } } open func tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -> Bool { - return invoke(action: .canMove, cell: tableView.cellForRow(at: indexPath), indexPath: indexPath) as? Bool ?? true + return invoke(action: .canMove, cell: tableView.cellForRow(at: indexPath), indexPath: indexPath) as? Bool ?? false } open func tableView(_ tableView: UITableView, moveRowAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath) { diff --git a/Sources/TableKit.swift b/Sources/TableKit.swift index f0cb0ff..91031b3 100644 --- a/Sources/TableKit.swift +++ b/Sources/TableKit.swift @@ -26,6 +26,7 @@ struct TableKitNotifications { public struct TableKitUserInfoKeys { public static let CellMoveDestinationIndexPath = "TableKitCellMoveDestinationIndexPath" + public static let CellCanMoveProposedIndexPath = "CellCanMoveProposedIndexPath" } public protocol RowConfigurable { @@ -76,7 +77,9 @@ public enum TableRowActionType { case height case canEdit case configure + case canDelete case canMove + case canMoveTo case move case custom(String) diff --git a/Sources/TablePrototypeCellHeightCalculator.swift b/Sources/TablePrototypeCellHeightCalculator.swift index 462d7a7..aa6341d 100644 --- a/Sources/TablePrototypeCellHeightCalculator.swift +++ b/Sources/TablePrototypeCellHeightCalculator.swift @@ -57,7 +57,7 @@ open class TablePrototypeCellHeightCalculator: RowHeightCalculator { cell.setNeedsLayout() cell.layoutIfNeeded() - let height = cell.contentView.systemLayoutSizeFitting(UILayoutFittingCompressedSize).height + (tableView.separatorStyle != .none ? separatorHeight : 0) + let height = cell.contentView.systemLayoutSizeFitting(UIView.layoutFittingCompressedSize).height + (tableView.separatorStyle != .none ? separatorHeight : 0) cachedHeights[hash] = height @@ -78,7 +78,7 @@ open class TablePrototypeCellHeightCalculator: RowHeightCalculator { return estimatedHeight } - return UITableViewAutomaticDimension + return UITableView.automaticDimension } open func invalidate() { diff --git a/Sources/TableRow.swift b/Sources/TableRow.swift index 5819bc7..d2d3bd3 100644 --- a/Sources/TableRow.swift +++ b/Sources/TableRow.swift @@ -22,7 +22,7 @@ import UIKit open class TableRow: Row where CellType: UITableViewCell { - open let item: CellType.T + public let item: CellType.CellData private lazy var actions = [String: [TableRowAction]]() private(set) open var editingActions: [UITableViewRowAction]? @@ -46,7 +46,7 @@ open class TableRow: Row where CellType: UITableView return CellType.self } - public init(item: CellType.T, actions: [TableRowAction]? = nil, editingActions: [UITableViewRowAction]? = nil) { + public init(item: CellType.CellData, actions: [TableRowAction]? = nil, editingActions: [UITableViewRowAction]? = nil) { self.item = item self.editingActions = editingActions @@ -69,7 +69,7 @@ open class TableRow: Row where CellType: UITableView open func invoke(action: TableRowActionType, cell: UITableViewCell?, path: IndexPath, userInfo: [AnyHashable: Any]? = nil) -> Any? { - return actions[action.key]?.flatMap({ $0.invokeActionOn(cell: cell, item: item, path: path, userInfo: userInfo) }).last + return actions[action.key]?.compactMap({ $0.invokeActionOn(cell: cell, item: item, path: path, userInfo: userInfo) }).last } open func has(action: TableRowActionType) -> Bool { diff --git a/Sources/TableRowAction.swift b/Sources/TableRowAction.swift index 73c7419..bee3d7a 100644 --- a/Sources/TableRowAction.swift +++ b/Sources/TableRowAction.swift @@ -22,12 +22,12 @@ import UIKit open class TableRowActionOptions where CellType: UITableViewCell { - open let item: CellType.T - open let cell: CellType? - open let indexPath: IndexPath - open let userInfo: [AnyHashable: Any]? + public let item: CellType.CellData + public let cell: CellType? + public let indexPath: IndexPath + public let userInfo: [AnyHashable: Any]? - init(item: CellType.T, cell: CellType?, path: IndexPath, userInfo: [AnyHashable: Any]?) { + init(item: CellType.CellData, cell: CellType?, path: IndexPath, userInfo: [AnyHashable: Any]?) { self.item = item self.cell = cell @@ -55,7 +55,7 @@ private enum TableRowActionHandler where CellType: U open class TableRowAction where CellType: UITableViewCell { open var id: String? - open let type: TableRowActionType + public let type: TableRowActionType private let handler: TableRowActionHandler public init(_ type: TableRowActionType, handler: @escaping (_ options: TableRowActionOptions) -> Void) { @@ -76,7 +76,7 @@ open class TableRowAction where CellType: UITableVie self.handler = .action(handler) } - public func invokeActionOn(cell: UITableViewCell?, item: CellType.T, path: IndexPath, userInfo: [AnyHashable: Any]?) -> Any? { + public func invokeActionOn(cell: UITableViewCell?, item: CellType.CellData, path: IndexPath, userInfo: [AnyHashable: Any]?) -> Any? { return handler.invoke(withOptions: TableRowActionOptions(item: item, cell: cell as? CellType, path: path, userInfo: userInfo)) } diff --git a/TableKit.podspec b/TableKit.podspec index 3e2852e..5d90f09 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 = '2.6.0' + s.version = '2.8.0' s.homepage = 'https://github.com/maxsokolov/TableKit' s.summary = 'Type-safe declarative table views with Swift.' diff --git a/TableKit.xcodeproj/project.pbxproj b/TableKit.xcodeproj/project.pbxproj index 6212938..9afc02f 100644 --- a/TableKit.xcodeproj/project.pbxproj +++ b/TableKit.xcodeproj/project.pbxproj @@ -177,16 +177,16 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0730; - LastUpgradeCheck = 0900; + LastUpgradeCheck = 1000; ORGANIZATIONNAME = "Max Sokolov"; TargetAttributes = { DA9EA7551D0B679A0021F650 = { CreatedOnToolsVersion = 7.3; - LastSwiftMigration = 0800; + LastSwiftMigration = 1000; }; DA9EA7C31D0EC45F0021F650 = { CreatedOnToolsVersion = 7.3; - LastSwiftMigration = 0800; + LastSwiftMigration = 1000; }; }; }; @@ -275,12 +275,14 @@ CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; @@ -333,12 +335,14 @@ CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; @@ -389,7 +393,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; }; name = Debug; }; @@ -409,7 +413,7 @@ PRODUCT_BUNDLE_IDENTIFIER = com.tablekit.TableKit; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; }; name = Release; }; @@ -421,7 +425,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.tablekit.TableKitTests; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; }; name = Debug; }; @@ -433,7 +437,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.tablekit.TableKitTests; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; }; name = Release; }; diff --git a/TableKit.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/TableKit.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/TableKit.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/TableKit.xcodeproj/xcshareddata/xcschemes/TableKit.xcscheme b/TableKit.xcodeproj/xcshareddata/xcschemes/TableKit.xcscheme index 9016615..d3c3b98 100644 --- a/TableKit.xcodeproj/xcshareddata/xcschemes/TableKit.xcscheme +++ b/TableKit.xcodeproj/xcshareddata/xcschemes/TableKit.xcscheme @@ -1,6 +1,6 @@