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

Commit 98a7c2c

Browse files
authored
Merge pull request #20 from nodes-ios/bugfix/swift4-infinite-loop
Bugfix/swift4 infinite loop
2 parents dc7c9a9 + 6314828 commit 98a7c2c

File tree

7 files changed

+57
-30
lines changed

7 files changed

+57
-30
lines changed

Sourcery/Sourcery/Classes/Sourcery/ComplexSourcery.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,10 @@ open class ComplexSourcery: NSObject, TableController {
9898
}
9999

100100
open func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
101-
if let constructor = sections[indexPath.section].customConstructors[indexPath.row] {
102-
return constructor(tableView, indexPath.row)
101+
let customConstructors = sections[indexPath.section].customConstructors
102+
if customConstructors.count > indexPath.row {
103+
let constructor = customConstructors[indexPath.row]
104+
return constructor!(tableView, indexPath.row)
103105
}
104106

105107
let type = sections[indexPath.section].cellType

Sourcery/SourceryExample/SourceryExample.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,9 +396,11 @@
396396
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
397397
EMBEDDED_CONTENT_CONTAINS_SWIFT = YES;
398398
INFOPLIST_FILE = "$(SRCROOT)/SourceryExample/Support/Info.plist";
399+
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
399400
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
400401
PRODUCT_BUNDLE_IDENTIFIER = com.nodes.SourceryExample;
401402
PRODUCT_NAME = "$(TARGET_NAME)";
403+
SWIFT_VERSION = 4.0;
402404
};
403405
name = Debug;
404406
};
@@ -408,9 +410,11 @@
408410
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
409411
EMBEDDED_CONTENT_CONTAINS_SWIFT = YES;
410412
INFOPLIST_FILE = "$(SRCROOT)/SourceryExample/Support/Info.plist";
413+
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
411414
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
412415
PRODUCT_BUNDLE_IDENTIFIER = com.nodes.SourceryExample;
413416
PRODUCT_NAME = "$(TARGET_NAME)";
417+
SWIFT_VERSION = 4.0;
414418
};
415419
name = Release;
416420
};
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>IDEDidComputeMac32BitWarning</key>
6+
<true/>
7+
</dict>
8+
</plist>

Sourcery/SourceryExample/SourceryExample/Classes/User Interface/Cells/ColorCell.swift

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,14 @@ class ColorCell: UITableViewCell {
1515

1616
override func awakeFromNib() {
1717
super.awakeFromNib()
18-
colorView.backgroundColor = UIColor.lightGrayColor()
18+
colorView.backgroundColor = UIColor.lightGray
1919
colorView.layer.cornerRadius = 2
20-
selectionStyle = .None
20+
selectionStyle = .none
2121
}
2222

2323
override func prepareForReuse() {
2424
super.prepareForReuse()
25-
colorView.backgroundColor = UIColor.lightGrayColor()
26-
}
25+
colorView.backgroundColor = UIColor.lightGray }
2726

2827
func populateWithColor(color: UIColor) {
2928
colorView.backgroundColor = color
@@ -34,4 +33,4 @@ extension ColorCell: TableViewPresentable {
3433
static var staticHeight: CGFloat {
3534
return 80.0
3635
}
37-
}
36+
}

Sourcery/SourceryExample/SourceryExample/Classes/User Interface/ComplexViewController.swift

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,31 @@ class ComplexViewController: UIViewController {
1515
var sourcery: ComplexSourcery?
1616

1717
let data = (texts: ["First row", "Second row", "Another row"],
18-
colors: [UIColor.redColor(), UIColor.yellowColor(), UIColor.blueColor()])
18+
colors: [UIColor.red, UIColor.yellow, UIColor.blue])
1919

2020
override func viewDidLoad() {
2121
super.viewDidLoad()
2222

23-
navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .Add, target: self, action: #selector(addSection))
24-
25-
let textSection = Section<String, BasicCell>(title: nil, data: data.texts, configurator: { $0.cell.textLabel?.text = $0.object }, selectionHandler: nil)
26-
let colorSection = Section<UIColor, ColorCell>(title: "Colors", data: data.colors, configurator: { $0.cell.populateWithColor($0.object) }, selectionHandler: nil, headerType: CustomHeaderView.self)
23+
navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .add, target: self, action: #selector(addSection))
2724

25+
let textSection = Section<String, BasicCell>(title: nil, data: data.texts, configurator: { (cell, index, object) in
26+
cell.textLabel?.text = object
27+
}, selectionHandler: nil)
28+
let colorSection = Section<UIColor, ColorCell>(title: "Colors", data: data.colors, configurator: { (cell, index, object) in
29+
cell.populateWithColor(color: object)
30+
}, selectionHandler: nil, headerType: CustomHeaderView.self)
2831
sourcery = ComplexSourcery(tableView: tableView, sections: [textSection, colorSection], headerConfigurator: { section, header, title in
2932
if let header = header as? CustomHeaderView {
3033
header.customTitleLabel.text = title
3134
}
3235
})
3336
}
3437

35-
func addSection() {
38+
@objc func addSection() {
3639
var sections = sourcery?.sections ?? []
37-
sections.append(Section<String, BasicCell>(title: "\(sections.count ?? 0 + 1)", data: data.texts, configurator: { $0.cell.textLabel?.text = $0.object }, selectionHandler: nil))
38-
sourcery?.updateSections(newSections: sections)
40+
sections.append(Section<String, BasicCell>(title: "\(sections.count ?? 0 + 1)", data: data.texts, configurator: { (cell, index, object) in
41+
cell.textLabel?.text = object
42+
}, selectionHandler: nil))
43+
sourcery?.update(sections: sections)
3944
}
4045
}

Sourcery/SourceryExample/SourceryExample/Classes/User Interface/PagedViewController.swift

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,29 @@ class PagedViewController: UIViewController {
2828
super.viewDidLoad()
2929
}
3030

31-
override func viewWillAppear(animated: Bool) {
31+
override func viewWillAppear(_ animated: Bool) {
3232
super.viewWillAppear(animated)
3333
setupSourcery()
3434
}
3535

3636
func setupSourcery() {
37-
let totalCount = data.reduce(0, combine: { $0.0 + $0.1.count })
38-
39-
sourcery = PagedSourcery<String, BasicCell>(tableView: tableView, pageSize: 3, pageLoader: { [weak self] (page, operationQueue, completion) in
40-
operationQueue.addOperationWithBlock({ [weak self] in
41-
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, Int64(0.5 * Double(NSEC_PER_SEC))), dispatch_get_main_queue(), { [weak self] in
42-
guard let strongSelf = self else { return }
43-
completion(totalCount: totalCount, data: strongSelf.data[page])
44-
})
45-
})
46-
}, configurator: { $0.cell.textLabel?.text = $0.object })
37+
let totalCount = data.reduce(0, { value, element in
38+
value + element.count
39+
})
40+
41+
sourcery = PagedSourcery<String, BasicCell>(tableView: tableView, pageSize: 3, pageLoader: {
42+
[weak self] (page, operationQueue, completion) in
43+
operationQueue.addOperation { [weak self] in
44+
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + .milliseconds(500), execute: {
45+
DispatchQueue.main.async {
46+
guard let strongSelf = self else { return }
47+
completion(totalCount, strongSelf.data[page])
48+
}
49+
})
50+
}
51+
}, configurator: { (cell, index, object) in
52+
cell.textLabel?.text = object
53+
})
4754
sourcery?.preloadMargin = nil
4855
}
4956
}

Sourcery/SourceryExample/SourceryExample/Classes/User Interface/SimpleViewController.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,18 @@ class SimpleViewController: UIViewController {
1818

1919
override func viewDidLoad() {
2020
super.viewDidLoad()
21-
22-
sourcery = SimpleSourcery<String, BasicCell>(tableView: tableView, data: data, configurator: { $0.cell.textLabel?.text = $0.object })
21+
sourcery = SimpleSourcery<String, BasicCell>(tableView: tableView, data: data, configurator: { (cell, index, object) in
22+
cell.textLabel?.text = object
23+
})
24+
// sourcery = SimpleSourcery<String, BasicCell>(tableView: tableView, data: data, configurator: { $0.cell.textLabel?.text = $0.object })
2325
}
2426

25-
override func viewWillAppear(animated: Bool) {
27+
override func viewWillAppear(_ animated: Bool) {
2628
super.viewWillAppear(animated)
2729

2830
var newData: [String] = (sourcery?.data ?? data)
2931
newData.append("New row")
30-
sourcery?.updateData(newData: newData)
32+
sourcery?.update(data: newData)
3133
}
3234
}
3335

0 commit comments

Comments
 (0)