Skip to content
This repository was archived by the owner on Mar 10, 2022. It is now read-only.

Commit 8ca00f1

Browse files
Jakob MygindJakob Mygind
authored andcommitted
- updated to Swift 3.0.1 and refactored to newer func syntax
1 parent fa90434 commit 8ca00f1

File tree

12 files changed

+170
-167
lines changed

12 files changed

+170
-167
lines changed

Cartfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
github "MrAlek/PagedArray" "swift2.3"
1+
github "MrAlek/PagedArray"

Cartfile.resolved

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
github "MrAlek/PagedArray" "e7bda3aea93b67daea8731389fb594ed7ea38544"
1+
github "MrAlek/PagedArray" "0.5"

Sourcery/Sourcery.xcodeproj/project.pbxproj

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -252,11 +252,11 @@
252252
TargetAttributes = {
253253
01DAF1371CCFB138003F7B1B = {
254254
CreatedOnToolsVersion = 7.3;
255-
LastSwiftMigration = 0800;
255+
LastSwiftMigration = 0810;
256256
};
257257
01DAF1411CCFB138003F7B1B = {
258258
CreatedOnToolsVersion = 7.3;
259-
LastSwiftMigration = 0800;
259+
LastSwiftMigration = 0810;
260260
};
261261
};
262262
};
@@ -376,6 +376,7 @@
376376
ONLY_ACTIVE_ARCH = YES;
377377
SDKROOT = iphoneos;
378378
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
379+
SWIFT_VERSION = 3.0.1;
379380
TARGETED_DEVICE_FAMILY = "1,2";
380381
VERSIONING_SYSTEM = "apple-generic";
381382
VERSION_INFO_PREFIX = "";
@@ -420,6 +421,7 @@
420421
MTL_ENABLE_DEBUG_INFO = NO;
421422
SDKROOT = iphoneos;
422423
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
424+
SWIFT_VERSION = 3.0.1;
423425
TARGETED_DEVICE_FAMILY = "1,2";
424426
VALIDATE_PRODUCT = YES;
425427
VERSIONING_SYSTEM = "apple-generic";
@@ -444,7 +446,7 @@
444446
PRODUCT_NAME = Sourcery;
445447
SKIP_INSTALL = YES;
446448
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
447-
SWIFT_VERSION = 2.3;
449+
SWIFT_VERSION = 3.0.1;
448450
};
449451
name = Debug;
450452
};
@@ -464,7 +466,7 @@
464466
PRODUCT_BUNDLE_IDENTIFIER = com.nodes.Sourcery;
465467
PRODUCT_NAME = Sourcery;
466468
SKIP_INSTALL = YES;
467-
SWIFT_VERSION = 2.3;
469+
SWIFT_VERSION = 3.0.1;
468470
};
469471
name = Release;
470472
};
@@ -475,7 +477,7 @@
475477
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks ${SRCROOT}/../Carthage/Build/iOS";
476478
PRODUCT_BUNDLE_IDENTIFIER = com.nodes.SourceryTests;
477479
PRODUCT_NAME = SourceryTests;
478-
SWIFT_VERSION = 2.3;
480+
SWIFT_VERSION = 3.0.1;
479481
};
480482
name = Debug;
481483
};
@@ -486,7 +488,7 @@
486488
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks ${SRCROOT}/../Carthage/Build/iOS";
487489
PRODUCT_BUNDLE_IDENTIFIER = com.nodes.SourceryTests;
488490
PRODUCT_NAME = SourceryTests;
489-
SWIFT_VERSION = 2.3;
491+
SWIFT_VERSION = 3.0.1;
490492
};
491493
name = Release;
492494
};

Sourcery/Sourcery/Classes/Extensions/Extensions.swift

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,36 +14,36 @@ public extension UITableView {
1414

1515
// MARK: Register
1616

17-
public func registerCellType(cellType: TableViewPresentable.Type) {
17+
public func register(cellType: TableViewPresentable.Type) {
1818
if cellType.loadsFromNib {
19-
self.registerNib(cellType.nib, forCellReuseIdentifier: cellType.reuseIdentifier)
19+
self.register(cellType.nib, forCellReuseIdentifier: cellType.reuseIdentifier)
2020
} else {
21-
self.registerClass(cellType, forCellReuseIdentifier: cellType.reuseIdentifier)
21+
self.register(cellType, forCellReuseIdentifier: cellType.reuseIdentifier)
2222
}
2323
}
2424

25-
public func registerCellType<T where T: TableViewPresentable>(cellType: T.Type) {
25+
public func register<T>(cellType: T.Type) where T: TableViewPresentable {
2626
if cellType.loadsFromNib {
27-
self.registerNib(cellType.nib, forCellReuseIdentifier: cellType.reuseIdentifier)
27+
self.register(cellType.nib, forCellReuseIdentifier: cellType.reuseIdentifier)
2828
} else {
29-
self.registerClass(cellType, forCellReuseIdentifier: cellType.reuseIdentifier)
29+
self.register(cellType, forCellReuseIdentifier: cellType.reuseIdentifier)
3030
}
3131
}
3232

33-
public func registerCellTypes(cellTypes: [TableViewPresentable.Type]) {
33+
public func register(cellTypes: [TableViewPresentable.Type]) {
3434
for cell in cellTypes {
35-
registerCellType(cell)
35+
register(cellType: cell)
3636
}
3737
}
3838

3939
// MARK: Dequeue
4040

41-
public func registerAndDequeueCell(cellType: TableViewPresentable.Type) -> UITableViewCell {
41+
public func registerAndDequeueCell(withCellType cellType: TableViewPresentable.Type) -> UITableViewCell {
4242
// First register
43-
registerCellType(cellType)
43+
register(cellType: cellType)
4444

4545
// Try to get cell or fail miserably
46-
guard let cell = self.dequeueReusableCellWithIdentifier(cellType.reuseIdentifier) else {
46+
guard let cell = self.dequeueReusableCell(withIdentifier: cellType.reuseIdentifier) else {
4747
fatalError("Cell registration and dequeue failed. Please check that " +
4848
"your NIB file exists or your class is available and set up correctly.")
4949
}
@@ -52,9 +52,9 @@ public extension UITableView {
5252
return cell
5353
}
5454

55-
public func dequeueCellType<T where T: TableViewPresentable>(cellType: TableViewPresentable.Type) -> T {
56-
var requestedCell = self.dequeueReusableCellWithIdentifier(cellType.reuseIdentifier) as? T
57-
requestedCell = requestedCell ?? registerAndDequeueCell(cellType) as? T
55+
public func dequeue<T>(cellType: TableViewPresentable.Type) -> T where T: TableViewPresentable {
56+
var requestedCell = self.dequeueReusableCell(withIdentifier: cellType.reuseIdentifier) as? T
57+
requestedCell = requestedCell ?? registerAndDequeueCell(withCellType: cellType) as? T
5858

5959
// This 'should never happen'
6060
guard let cell = requestedCell else {
@@ -65,27 +65,27 @@ public extension UITableView {
6565
return cell
6666
}
6767

68-
public func dequeueCellTypeDefault(cellType: TableViewPresentable.Type) -> UITableViewCell {
69-
let cell = self.dequeueReusableCellWithIdentifier(cellType.reuseIdentifier)
70-
return cell ?? registerAndDequeueCell(cellType)
68+
public func dequeueDefault(cellType: TableViewPresentable.Type) -> UITableViewCell {
69+
let cell = self.dequeueReusableCell(withIdentifier: cellType.reuseIdentifier)
70+
return cell ?? registerAndDequeueCell(withCellType: cellType)
7171
}
7272

7373
// MARK: Header & Footer
7474

7575
public func registerHeaderFooterView(viewType: TableViewPresentable.Type) {
7676
if viewType.loadsFromNib {
77-
self.registerNib(viewType.nib, forHeaderFooterViewReuseIdentifier: viewType.reuseIdentifier)
77+
self.register(viewType.nib, forHeaderFooterViewReuseIdentifier: viewType.reuseIdentifier)
7878
} else {
79-
self.registerClass(viewType, forHeaderFooterViewReuseIdentifier: viewType.reuseIdentifier)
79+
self.register(viewType, forHeaderFooterViewReuseIdentifier: viewType.reuseIdentifier)
8080
}
8181
}
8282

8383
public func registerAndDequeueHeaderFooterView(viewType: TableViewPresentable.Type) -> UITableViewHeaderFooterView? {
8484
// First register
85-
registerHeaderFooterView(viewType)
85+
registerHeaderFooterView(viewType: viewType)
8686

8787
// Try to get cell or fail miserably
88-
guard let view = self.dequeueReusableHeaderFooterViewWithIdentifier(viewType.reuseIdentifier) else {
88+
guard let view = self.dequeueReusableHeaderFooterView(withIdentifier: viewType.reuseIdentifier) else {
8989
fatalError("Header/Footer view registration and dequeue failed. Please check that " +
9090
"your NIB file exists or your class is available and set up correctly.")
9191
}
@@ -94,9 +94,9 @@ public extension UITableView {
9494
return view
9595
}
9696

97-
public func dequeueHeaderFooterView(viewType: TableViewPresentable.Type) -> UITableViewHeaderFooterView? {
98-
var requestedView = self.dequeueReusableHeaderFooterViewWithIdentifier(viewType.reuseIdentifier)
99-
requestedView = requestedView ?? registerAndDequeueHeaderFooterView(viewType)
97+
public func dequeueHeaderFooterView(_ viewType: TableViewPresentable.Type) -> UITableViewHeaderFooterView? {
98+
var requestedView = self.dequeueReusableHeaderFooterView(withIdentifier: viewType.reuseIdentifier)
99+
requestedView = requestedView ?? registerAndDequeueHeaderFooterView(viewType: viewType)
100100

101101
// This 'should never happen'
102102
guard let view = requestedView else {
@@ -106,4 +106,4 @@ public extension UITableView {
106106

107107
return view
108108
}
109-
}
109+
}

Sourcery/Sourcery/Classes/Protocols/SectionType.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import UIKit
1010

11-
public typealias CellConstructor = ((tableView: UITableView, index: Int) -> UITableViewCell)
11+
public typealias CellConstructor = ((_ tableView: UITableView, _ index: Int) -> UITableViewCell)
1212

1313
public protocol SectionType {
1414
var dataCount: Int { get }
@@ -18,7 +18,7 @@ public protocol SectionType {
1818
var customConstructors: [Int: CellConstructor] { get set }
1919
var headerType: TableViewPresentable.Type? { get set }
2020

21-
func heightForCellAtIndex(index: Int) -> CGFloat
22-
func configureCell(cell: UITableViewCell, index: Int)
23-
func handleSelection(index: Int)
21+
func heightForCell(atIndex index: Int) -> CGFloat
22+
func configure(cell: UITableViewCell, index: Int)
23+
func handle(selection index: Int)
2424
}

Sourcery/Sourcery/Classes/Protocols/TableViewDelegateProxy.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ import Foundation
1010
import UIKit
1111

1212
public protocol TableViewDelegateProxy: class {
13-
func scrollViewDidScroll(scrollView: UIScrollView)
14-
}
13+
func scrollViewDidScroll(_ scrollView: UIScrollView)
14+
}

Sourcery/Sourcery/Classes/Protocols/TableViewPresentable.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import UIKit
1010

11-
public typealias TableController = protocol<UITableViewDataSource, UITableViewDelegate>
11+
public typealias TableController = UITableViewDataSource & UITableViewDelegate
1212

1313
public protocol TableViewPresentable: NibInstantiable {
1414
static var nib: UINib { get }
@@ -19,15 +19,15 @@ public protocol TableViewPresentable: NibInstantiable {
1919

2020
public extension TableViewPresentable {
2121
public static var nib: UINib {
22-
return UINib(nibName: String(self), bundle: nil)
22+
return UINib(nibName: String(describing: self), bundle: nil)
2323
}
2424

2525
public static func newFromNib<T>() -> T {
26-
return nib.instantiateWithOwner(nil, options: nil).first as! T
26+
return nib.instantiate(withOwner: nil, options: nil).first as! T
2727
}
2828

2929
public static var reuseIdentifier: String {
30-
return String(self)
30+
return String(describing: self)
3131
}
3232

3333
public static var loadsFromNib: Bool {

Sourcery/Sourcery/Classes/Section/Section.swift

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ import UIKit
1010

1111
public struct Section<DataType, CellType: TableViewPresentable>: SectionType {
1212

13-
public typealias SelectionHandler = ((index: Int, object: DataType) -> Void)
14-
public typealias CellConfigurator = ((cell: CellType, index: Int, object: DataType) -> Void)
15-
public typealias HeightConfigurator = ((index: Int, object: DataType) -> CGFloat)
13+
public typealias SelectionHandler = ((_ index: Int, _ object: DataType) -> Void)
14+
public typealias CellConfigurator = ((_ cell: CellType, _ index: Int, _ object: DataType) -> Void)
15+
public typealias HeightConfigurator = ((_ index: Int, _ object: DataType) -> CGFloat)
1616

17-
public private(set) var data = [DataType]()
18-
private var selectionHandler: SelectionHandler?
19-
private var configurator: CellConfigurator?
20-
private var heightConfigurator: HeightConfigurator?
17+
public fileprivate(set) var data = [DataType]()
18+
fileprivate var selectionHandler: SelectionHandler?
19+
fileprivate var configurator: CellConfigurator?
20+
fileprivate var heightConfigurator: HeightConfigurator?
2121

22-
public private(set) var title: String?
22+
public fileprivate(set) var title: String?
2323

2424
public var customConstructors: [Int: CellConstructor] = [:]
2525

@@ -42,15 +42,15 @@ public struct Section<DataType, CellType: TableViewPresentable>: SectionType {
4242
self.headerType = headerType
4343
}
4444

45-
public func configureCell(cell: UITableViewCell, index: Int) {
46-
configurator?(cell: cell as! CellType, index: index, object: data[index])
45+
public func configure(cell: UITableViewCell, index: Int) {
46+
configurator?(cell as! CellType, index, data[index])
4747
}
4848

49-
public func handleSelection(index: Int) {
50-
selectionHandler?(index: index, object: data[index])
49+
public func handle(selection index: Int) {
50+
selectionHandler?(index, data[index])
5151
}
5252

53-
public func heightForCellAtIndex(index: Int) -> CGFloat {
54-
return heightConfigurator?(index: index, object: data[index]) ?? CellType.staticHeight
53+
public func heightForCell(atIndex index: Int) -> CGFloat {
54+
return heightConfigurator?(index, data[index]) ?? CellType.staticHeight
5555
}
56-
}
56+
}

0 commit comments

Comments
 (0)