diff --git a/.gitignore b/.gitignore index b08b1c9..914ef36 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,34 @@ +# Xcode +# +# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore + +## Build generated +build/ +DerivedData/ + +## Various settings +*.pbxuser +!default.pbxuser +*.mode1v3 +!default.mode1v3 +*.mode2v3 +!default.mode2v3 +*.perspectivev3 +!default.perspectivev3 +xcuserdata/ + +## Other +*.moved-aside +*.xcuserstate +.DS_Store +*.swp +*.lock + +## Obj-C/Swift specific +*.hmap +*.ipa +*.dSYM.zip +*.dSYM + + Carthage diff --git a/Cartfile.resolved b/Cartfile.resolved index e629cf5..06a76c1 100644 --- a/Cartfile.resolved +++ b/Cartfile.resolved @@ -1,2 +1,2 @@ -github "Quick/Nimble" "v4.0.1" -github "Quick/Quick" "v0.9.2" +github "Quick/Nimble" "v5.0.0" +github "Quick/Quick" "v0.10.0" diff --git a/DataSourceable.xcodeproj/project.pbxproj b/DataSourceable.xcodeproj/project.pbxproj index 71ca6b6..40fb267 100644 --- a/DataSourceable.xcodeproj/project.pbxproj +++ b/DataSourceable.xcodeproj/project.pbxproj @@ -243,14 +243,18 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0700; - LastUpgradeCheck = 0700; + LastUpgradeCheck = 0800; ORGANIZATIONNAME = "Zeker Waar"; TargetAttributes = { B3E89A821BCCDFB900C0FB4C = { CreatedOnToolsVersion = 7.0.1; + DevelopmentTeam = RS662E2L2G; + LastSwiftMigration = 0800; }; B3E89A8C1BCCDFBA00C0FB4C = { CreatedOnToolsVersion = 7.0.1; + DevelopmentTeam = RS662E2L2G; + LastSwiftMigration = 0800; }; }; }; @@ -368,8 +372,10 @@ 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_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; @@ -416,8 +422,10 @@ 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_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; @@ -437,6 +445,7 @@ IPHONEOS_DEPLOYMENT_TARGET = 9.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; + SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; VERSIONING_SYSTEM = "apple-generic"; @@ -448,7 +457,9 @@ isa = XCBuildConfiguration; buildSettings = { CLANG_ENABLE_MODULES = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; DEFINES_MODULE = YES; + DEVELOPMENT_TEAM = RS662E2L2G; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; @@ -460,6 +471,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 3.0; }; name = Debug; }; @@ -467,7 +479,9 @@ isa = XCBuildConfiguration; buildSettings = { CLANG_ENABLE_MODULES = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; DEFINES_MODULE = YES; + DEVELOPMENT_TEAM = RS662E2L2G; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; @@ -478,12 +492,14 @@ PRODUCT_BUNDLE_IDENTIFIER = nl.zekerwaar.DataSourceable; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; + SWIFT_VERSION = 3.0; }; name = Release; }; B3E89A9B1BCCDFBA00C0FB4C /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + DEVELOPMENT_TEAM = RS662E2L2G; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", "$(PROJECT_DIR)/Carthage/Build/iOS", @@ -492,12 +508,14 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = nl.zekerwaar.DataSourceableTests; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; }; name = Debug; }; B3E89A9C1BCCDFBA00C0FB4C /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + DEVELOPMENT_TEAM = RS662E2L2G; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", "$(PROJECT_DIR)/Carthage/Build/iOS", @@ -506,6 +524,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = nl.zekerwaar.DataSourceableTests; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; }; name = Release; }; diff --git a/DataSourceable.xcodeproj/xcshareddata/xcschemes/DataSourceable.xcscheme b/DataSourceable.xcodeproj/xcshareddata/xcschemes/DataSourceable.xcscheme index a604f79..9f71152 100644 --- a/DataSourceable.xcodeproj/xcshareddata/xcschemes/DataSourceable.xcscheme +++ b/DataSourceable.xcodeproj/xcshareddata/xcschemes/DataSourceable.xcscheme @@ -1,6 +1,6 @@ String + func reuseIdentifier(forIndexPath indexPath: IndexPath) -> String } public protocol TableViewCellProviding: CellProviding { @@ -16,4 +16,4 @@ public protocol TableViewCellProviding: CellProviding { public protocol CollectionViewCellProviding: CellProviding { associatedtype CollectionViewCellType: Configurable -} \ No newline at end of file +} diff --git a/DataSourceable/CollectionViewDataSource.swift b/DataSourceable/CollectionViewDataSource.swift index 2e4ed3d..a1d99af 100644 --- a/DataSourceable/CollectionViewDataSource.swift +++ b/DataSourceable/CollectionViewDataSource.swift @@ -7,47 +7,47 @@ // public protocol CollectionViewDataSource { - func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int - func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell - func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int - func collectionView(collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, atIndexPath indexPath: NSIndexPath) -> UICollectionReusableView - func collectionView(collectionView: UICollectionView, canMoveItemAtIndexPath indexPath: NSIndexPath) -> Bool - func collectionView(collectionView: UICollectionView, moveItemAtIndexPath sourceIndexPath: NSIndexPath, toIndexPath destinationIndexPath: NSIndexPath) + func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int + func collectionView(_ collectionView: UICollectionView, cellForItemAtIndexPath indexPath: IndexPath) -> UICollectionViewCell + func numberOfSectionsInCollectionView(_ collectionView: UICollectionView) -> Int + func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, atIndexPath indexPath: IndexPath) -> UICollectionReusableView + func collectionView(_ collectionView: UICollectionView, canMoveItemAtIndexPath indexPath: IndexPath) -> Bool + func collectionView(_ collectionView: UICollectionView, moveItemAtIndexPath sourceIndexPath: IndexPath, toIndexPath destinationIndexPath: IndexPath) } public extension CollectionViewDataSource { - func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int { + func numberOfSectionsInCollectionView(_ collectionView: UICollectionView) -> Int { return 1 } - func collectionView(collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, atIndexPath indexPath: NSIndexPath) -> UICollectionReusableView { - return collectionView.dequeueReusableSupplementaryViewOfKind(kind, withReuseIdentifier: "", forIndexPath: indexPath) + func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, atIndexPath indexPath: IndexPath) -> UICollectionReusableView { + return collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "", for: indexPath) } - func collectionView(collectionView: UICollectionView, canMoveItemAtIndexPath indexPath: NSIndexPath) -> Bool { + func collectionView(_ collectionView: UICollectionView, canMoveItemAtIndexPath indexPath: IndexPath) -> Bool { return false } - func collectionView(collectionView: UICollectionView, moveItemAtIndexPath sourceIndexPath: NSIndexPath, toIndexPath destinationIndexPath: NSIndexPath) { + func collectionView(_ collectionView: UICollectionView, moveItemAtIndexPath sourceIndexPath: IndexPath, toIndexPath destinationIndexPath: IndexPath) { } } public extension CollectionViewDataSource where Self: Sectionable { - func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { + func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { return numberOfItems(inSection: section) } - func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int { + func numberOfSectionsInCollectionView(_ collectionView: UICollectionView) -> Int { return numberOfSections } } public extension CollectionViewDataSource where Self: Sectionable, Self: CollectionViewCellProviding, Self.CollectionViewCellType.ItemType == Self.Section.Data.Element { - func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { + func collectionView(_ collectionView: UICollectionView, cellForItemAtIndexPath indexPath: IndexPath) -> UICollectionViewCell { let identifier = reuseIdentifier(forIndexPath: indexPath) guard let item = item(atIndexPath: indexPath) else { return UICollectionViewCell() } - let cell = collectionView.dequeueReusableCellWithReuseIdentifier(identifier, forIndexPath: indexPath) - if let cell = cell as? CollectionViewCellType, view = collectionView as? CollectionViewCellType.ContainingViewType { + let cell = collectionView.dequeueReusableCell(withReuseIdentifier: identifier, for: indexPath) + if let cell = cell as? CollectionViewCellType, let view = collectionView as? CollectionViewCellType.ContainingViewType { cell.configure(forItem: item, inView: view) } return cell diff --git a/DataSourceable/CollectionViewDataSourceProxy.swift b/DataSourceable/CollectionViewDataSourceProxy.swift index 4e7554f..c6db447 100644 --- a/DataSourceable/CollectionViewDataSourceProxy.swift +++ b/DataSourceable/CollectionViewDataSourceProxy.swift @@ -6,32 +6,32 @@ // Copyright © 2015 Zeker Waar. All rights reserved. // -public class CollectionViewDataSourceProxy: NSObject, UICollectionViewDataSource { - public let dataSource: CollectionViewDataSource +open class CollectionViewDataSourceProxy: NSObject, UICollectionViewDataSource { + open let dataSource: CollectionViewDataSource public init(dataSource: CollectionViewDataSource) { self.dataSource = dataSource } - public func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { + open func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { return dataSource.collectionView(collectionView, numberOfItemsInSection: section) } - public func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { + open func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { return dataSource.collectionView(collectionView, cellForItemAtIndexPath: indexPath) } - public func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int { + open func numberOfSections(in collectionView: UICollectionView) -> Int { return dataSource.numberOfSectionsInCollectionView(collectionView) } - public func collectionView(collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, atIndexPath indexPath: NSIndexPath) -> UICollectionReusableView { + open func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView { return dataSource.collectionView(collectionView, viewForSupplementaryElementOfKind: kind, atIndexPath: indexPath) } - public func collectionView(collectionView: UICollectionView, canMoveItemAtIndexPath indexPath: NSIndexPath) -> Bool { + open func collectionView(_ collectionView: UICollectionView, canMoveItemAt indexPath: IndexPath) -> Bool { return dataSource.collectionView(collectionView, canMoveItemAtIndexPath: indexPath) } - public func collectionView(collectionView: UICollectionView, moveItemAtIndexPath sourceIndexPath: NSIndexPath, toIndexPath destinationIndexPath: NSIndexPath) { + open func collectionView(_ collectionView: UICollectionView, moveItemAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath) { return dataSource.collectionView(collectionView, moveItemAtIndexPath: sourceIndexPath, toIndexPath: destinationIndexPath) } } diff --git a/DataSourceable/ElementsContaining.swift b/DataSourceable/ElementsContaining.swift index 911645b..0429eaf 100644 --- a/DataSourceable/ElementsContaining.swift +++ b/DataSourceable/ElementsContaining.swift @@ -12,7 +12,7 @@ public protocol ElementsContaining { subscript(index: Int) -> Element? { get } } -extension Indexable where Index == Int { +extension Collection where Index == Int { var count: Int { return endIndex } diff --git a/DataSourceable/Loadable.swift b/DataSourceable/Loadable.swift index 0ce7a1c..d70707e 100644 --- a/DataSourceable/Loadable.swift +++ b/DataSourceable/Loadable.swift @@ -7,24 +7,24 @@ // public enum Result { - case Success(Value) - case Failure(E) + case success(Value) + case failure(E) } public protocol Loadable: class { associatedtype Data : EmptyCheckable - var state: State { get set } - func loadData(completion: (Result) -> Void) + var state: State { get set } + func loadData(_ completion: @escaping(Result) -> Void) } public extension Loadable { - func reload(completion: () -> Void) { + func reload(_ completion: @escaping () -> Void) { state = state.toLoading() loadData { result in switch result { - case .Success(let data): + case .success(let data): self.state = self.state.toReady(data) - case .Failure(let error): + case .failure(let error): self.state = self.state.toError(error) } completion() diff --git a/DataSourceable/Sectionable.swift b/DataSourceable/Sectionable.swift index ed2fa55..f98b0aa 100644 --- a/DataSourceable/Sectionable.swift +++ b/DataSourceable/Sectionable.swift @@ -14,7 +14,7 @@ public protocol Sectionable { public protocol SectionCreating: Sectionable { associatedtype Data var data: Data? { get } - func createSections(data: Data) -> [Section] + func createSections(_ data: Data) -> [Section] } public extension Sectionable { @@ -33,8 +33,8 @@ public extension Sectionable { return section(atIndex: sectionIndex)?.numberOfItems ?? 0 } - func item(atIndexPath indexPath: NSIndexPath) -> Section.Data.Element? { - return section(atIndex: indexPath.section)?.item(atIndex: indexPath.row) + func item(atIndexPath indexPath: IndexPath) -> Section.Data.Element? { + return section(atIndex: (indexPath as NSIndexPath).section)?.item(atIndex: (indexPath as NSIndexPath).row) } func sectionHeader(atIndex index: Int) -> String? { @@ -62,4 +62,4 @@ public extension Sectionable where Self : DataContaining, Self.Data == [Section] var sections: [Section]? { return data } -} \ No newline at end of file +} diff --git a/DataSourceable/State.swift b/DataSourceable/State.swift index a443812..efd266b 100644 --- a/DataSourceable/State.swift +++ b/DataSourceable/State.swift @@ -7,23 +7,23 @@ // public enum State { - case Empty - case Loading(D?) - case Ready(D) + case empty + case loading(D?) + case ready(D) case Error(E,D?) public func toLoading() -> State { switch self { - case .Ready(let oldData): - return .Loading(oldData) + case .ready(let oldData): + return .loading(oldData) default: - return .Loading(nil) + return .loading(nil) } } - public func toError(error:E) -> State { + public func toError(_ error:E) -> State { switch self { - case .Loading(let oldData): + case .loading(let oldData): return .Error(error,oldData) default: assert(false, "Invalid state transition to .Error from other than .Loading") @@ -31,13 +31,13 @@ public enum State { } } - public func toReady(data: D) -> State { + public func toReady(_ data: D) -> State { switch self { - case .Loading: + case .loading: if data.isEmpty { - return .Empty + return .empty } else { - return .Ready(data) + return .ready(data) } default: assert(false, "Invalid state transition to .Ready from other than .Loading") @@ -47,11 +47,11 @@ public enum State { public var data: D? { switch self { - case .Empty: + case .empty: return nil - case .Ready(let data): + case .ready(let data): return data - case .Loading(let data): + case .loading(let data): return data case .Error(_, let data): return data diff --git a/DataSourceable/TableViewDataSource.swift b/DataSourceable/TableViewDataSource.swift index 84d35c0..ef6eb3d 100644 --- a/DataSourceable/TableViewDataSource.swift +++ b/DataSourceable/TableViewDataSource.swift @@ -7,41 +7,41 @@ // public protocol TableViewDataSource { - func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int - func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell - func numberOfSectionsInTableView(tableView: UITableView) -> Int - func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? - func tableView(tableView: UITableView, titleForFooterInSection section: Int) -> String? + func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int + func tableView(_ tableView: UITableView, cellForRowAtIndexPath indexPath: IndexPath) -> UITableViewCell + func numberOfSectionsInTableView(_ tableView: UITableView) -> Int + func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? + func tableView(_ tableView: UITableView, titleForFooterInSection section: Int) -> String? } public extension TableViewDataSource { - public func numberOfSectionsInTableView(tableView: UITableView) -> Int { + public func numberOfSectionsInTableView(_ tableView: UITableView) -> Int { return 1 } - public func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? { + public func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? { return nil } - public func tableView(tableView: UITableView, titleForFooterInSection section: Int) -> String? { + public func tableView(_ tableView: UITableView, titleForFooterInSection section: Int) -> String? { return nil } } public extension TableViewDataSource where Self: Sectionable { - public func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return numberOfItems(inSection: section) } - public func numberOfSectionsInTableView(tableView: UITableView) -> Int { + public func numberOfSectionsInTableView(_ tableView: UITableView) -> Int { return numberOfSections } - public func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? { + public func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? { return sectionHeader(atIndex: section) } - public func tableView(tableView: UITableView, titleForFooterInSection section: Int) -> String? { + public func tableView(_ tableView: UITableView, titleForFooterInSection section: Int) -> String? { return sectionFooter(atIndex: section) } } @@ -50,13 +50,13 @@ public extension TableViewDataSource where Self: Sectionable { public extension TableViewDataSource where Self: Sectionable, Self: TableViewCellProviding, Self.TableViewCellType.ItemType == Self.Section.Data.Element { - func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { + func tableView(_ tableView: UITableView, cellForRowAtIndexPath indexPath: IndexPath) -> UITableViewCell { let identifier = reuseIdentifier(forIndexPath: indexPath) guard let item = item(atIndexPath: indexPath) else { - return tableView.dequeueReusableCellWithIdentifier(identifier) ?? UITableViewCell() + return tableView.dequeueReusableCell(withIdentifier: identifier) ?? UITableViewCell() } - let cell = tableView.dequeueReusableCellWithIdentifier(identifier, forIndexPath: indexPath) - if let cell = cell as? TableViewCellType, view = tableView as? TableViewCellType.ContainingViewType { + let cell = tableView.dequeueReusableCell(withIdentifier: identifier, for: indexPath) + if let cell = cell as? TableViewCellType, let view = tableView as? TableViewCellType.ContainingViewType { cell.configure(forItem: item, inView: view) } return cell diff --git a/DataSourceable/TableViewDataSourceProxy.swift b/DataSourceable/TableViewDataSourceProxy.swift index dfdd122..28838db 100644 --- a/DataSourceable/TableViewDataSourceProxy.swift +++ b/DataSourceable/TableViewDataSourceProxy.swift @@ -6,30 +6,30 @@ // Copyright © 2015 Zeker Waar. All rights reserved. // -public class TableViewDataSourceProxy: NSObject, UITableViewDataSource { - public let dataSource: TableViewDataSource +open class TableViewDataSourceProxy: NSObject, UITableViewDataSource { + open let dataSource: TableViewDataSource public init(dataSource: TableViewDataSource) { self.dataSource = dataSource } - public func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + open func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return dataSource.tableView(tableView, numberOfRowsInSection: section) } - public func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { + open func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { return dataSource.tableView(tableView, cellForRowAtIndexPath: indexPath) } - public func numberOfSectionsInTableView(tableView: UITableView) -> Int { + open func numberOfSections(in tableView: UITableView) -> Int { return dataSource.numberOfSectionsInTableView(tableView) } - public func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? { + open func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? { return dataSource.tableView(tableView, titleForHeaderInSection: section) } - public func tableView(tableView: UITableView, titleForFooterInSection section: Int) -> String? { + open func tableView(_ tableView: UITableView, titleForFooterInSection section: Int) -> String? { return dataSource.tableView(tableView, titleForFooterInSection: section) } -} \ No newline at end of file +} diff --git a/DataSourceableTests/CollectionViewDataSourceableSpec.swift b/DataSourceableTests/CollectionViewDataSourceableSpec.swift index 5f0b828..1c99fed 100644 --- a/DataSourceableTests/CollectionViewDataSourceableSpec.swift +++ b/DataSourceableTests/CollectionViewDataSourceableSpec.swift @@ -13,9 +13,9 @@ import Nimble struct SimpleCollectionViewDataSource: CollectionViewDataSourceable { typealias ItemType = UIColor - var sections: [[UIColor]]? = [[UIColor.redColor(),UIColor.blueColor(),UIColor.greenColor()],[UIColor.blackColor(),UIColor.whiteColor()],[UIColor.yellowColor(),UIColor.purpleColor(),UIColor.orangeColor(),UIColor.magentaColor()]] + var sections: [[UIColor]]? = [[.red, .blue, .green],[.black, .white],[.yellow,.purple,.orange,.magenta]] - func reuseIdentifier(forIndexPath indexPath: NSIndexPath) -> String { + func reuseIdentifier(forIndexPath indexPath: IndexPath) -> String { return "identifier" } } @@ -35,8 +35,8 @@ extension SimpleCollectionViewDataSource: CollectionViewCellProviding { class CollectionViewDataSourceableSpec: QuickSpec { override func spec() { describe("CollectionViewDataSourceable") { - let collectionView = UICollectionView(frame: CGRectZero, collectionViewLayout: UICollectionViewFlowLayout()) - collectionView.registerClass(UICollectionViewCell.self, forCellWithReuseIdentifier: "identifier") + let collectionView = UICollectionView(frame: CGRect.zero, collectionViewLayout: UICollectionViewFlowLayout()) + collectionView.register(UICollectionViewCell.self, forCellWithReuseIdentifier: "identifier") context("with a simple tableview data source") { let simpleDataSource = SimpleCollectionViewDataSource() let proxy = CollectionViewDataSourceProxy(dataSource: simpleDataSource) @@ -50,22 +50,22 @@ class CollectionViewDataSourceableSpec: QuickSpec { } describe("numberOfSectionsInCollectionView") { it("should return 0") { - expect(collectionView.dataSource!.numberOfSectionsInCollectionView!(collectionView)).to(equal(3)) + expect(collectionView.dataSource!.numberOfSections!(in: collectionView)).to(equal(3)) } } describe("cellForItemAtIndexPath") { it("should return the configured cell") { - for section in 0.. = .Empty - func loadData(completion: (Result<[Int],ErrorType>) -> Void) { - dispatch_async(dispatch_get_global_queue(QOS_CLASS_BACKGROUND, 0)) { - completion(Result.Success(self.fixtureData)) + var state: State<[Int],Error> = .empty + func loadData(_ completion: @escaping (Result<[Int],Error>) -> Void) { + DispatchQueue.global().async { + completion(Result.success(self.fixtureData)) } } init(fixtureData: [Int]) { @@ -28,18 +28,20 @@ class LoadingDataSource: Loadable { } class FailingDataSource: LoadingDataSource { - override func loadData(completion: (Result<[Int],ErrorType>) -> Void) { - completion(Result.Failure(Error.Fail)) + + override func loadData(_ completion: @escaping (Result<[Int],Error>) -> Void) { + completion(Result.failure(DataSourcableError.fail)) } + } extension State: Equatable {} public func ==(lhs: State, rhs: State) -> Bool { switch (lhs,rhs) { - case (.Empty,.Empty): return true - case (.Loading,.Loading): return true - case (.Ready,.Ready): return true + case (.empty,.empty): return true + case (.loading,.loading): return true + case (.ready,.ready): return true case (.Error,.Error): return true default: return false } @@ -68,7 +70,7 @@ class LoadableSpec: QuickSpec { it("moves to the error state") { loading.reload({ }) - let errorState: State<[Int],ErrorType> = .Error(Error.Fail,nil) + let errorState: State<[Int],Error> = .Error(DataSourcableError.fail,nil) expect(loading.state).toEventually(equal(errorState)) } } diff --git a/DataSourceableTests/SectionableSpec.swift b/DataSourceableTests/SectionableSpec.swift index c01c58f..744acee 100644 --- a/DataSourceableTests/SectionableSpec.swift +++ b/DataSourceableTests/SectionableSpec.swift @@ -58,7 +58,7 @@ class SectionableSpec: QuickSpec { it("should return the right items") { for sectionIndex in 0.. String? { - return data?.keys.sort()[sectionIndex] + func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? { + return data?.keys.sorted()[section] } + } extension SimpleTableViewDataSource: TableViewCellProviding { @@ -34,8 +35,8 @@ extension SimpleTableViewDataSource: TableViewCellProviding { extension SimpleTableViewDataSource: SectionCreating { typealias Section = [Int] - func createSections(data: [String:[Int]]) -> [Section] { - return data.keys.sort().flatMap { data[$0] } + func createSections(_ data: [String:[Int]]) -> [Section] { + return data.keys.sorted().flatMap { data[$0] } } } @@ -59,7 +60,7 @@ extension UITableViewCell: Configurable { protocol TestTableViewSourceable: TableViewDataSourceable {} extension TestTableViewSourceable { - func reuseIdentifier(forIndexPath indexPath: NSIndexPath) -> String { + func reuseIdentifier(forIndexPath indexPath: IndexPath) -> String { return "identifier" } } @@ -67,8 +68,8 @@ extension TestTableViewSourceable { class TableViewDataSourceableSpec: QuickSpec { override func spec() { describe("TableViewDataSourceable") { - let tableView = UITableView(frame: CGRect(x: 0, y: 0, width: 100, height: 100), style: .Plain) - tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "identifier") + let tableView = UITableView(frame: CGRect(x: 0, y: 0, width: 100, height: 100), style: .plain) + tableView.register(UITableViewCell.self, forCellReuseIdentifier: "identifier") context("with a simple tableview data source") { let simpleDataSource = SimpleTableViewDataSource() let proxy = TableViewDataSourceProxy(dataSource: simpleDataSource) @@ -82,14 +83,14 @@ class TableViewDataSourceableSpec: QuickSpec { } describe("numberOfSectionsInTableView") { it("should return 0") { - expect(tableView.dataSource!.numberOfSectionsInTableView!(tableView)).to(equal(3)) + expect(tableView.dataSource!.numberOfSections!(in: tableView)).to(equal(3)) } } describe("titleForHeaderInSection") { it("should override the default implementation") { let titles = ["a","b","c"] - for index in 0..<3 { + for index in 0.. String { + func reuseIdentifier(forIndexPath indexPath: IndexPath) -> String { return defaultReuseIdentifier } } @@ -33,7 +33,8 @@ extension MovieTitleDataSource: TableViewCellProviding { let tableView: UITableView = UITableView(frame: CGRect(x: 0, y: 0, width: 320, height: 500)) let dataSource = MovieTitleDataSource() let proxy = TableViewDataSourceProxy(dataSource: dataSource) -tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: defaultReuseIdentifier) +tableView.register(UITableViewCell.self, forCellReuseIdentifier: defaultReuseIdentifier) tableView.dataSource = proxy -XCPlaygroundPage.currentPage.liveView = tableView + +PlaygroundPage.current.liveView = tableView