Skip to content

Commit f2a14d1

Browse files
committed
Make reloading sections an array. Fixed section deletion range logic. Hooked up tests.
1 parent 9afaa9b commit f2a14d1

4 files changed

Lines changed: 35 additions & 5 deletions

File tree

Static.xcodeproj/project.pbxproj

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@
4949
remoteGlobalIDString = 21826AA91B3F51A100AA9641;
5050
remoteInfo = "Static-iOS";
5151
};
52+
3B1129252226E5D800B6E06A /* PBXContainerItemProxy */ = {
53+
isa = PBXContainerItemProxy;
54+
containerPortal = 21826AA11B3F51A100AA9641 /* Project object */;
55+
proxyType = 1;
56+
remoteGlobalIDString = 36748D4E1B5034EC0046F207;
57+
remoteInfo = Example;
58+
};
5259
/* End PBXContainerItemProxy section */
5360

5461
/* Begin PBXCopyFilesBuildPhase section */
@@ -242,6 +249,7 @@
242249
);
243250
dependencies = (
244251
21826AB71B3F51A100AA9641 /* PBXTargetDependency */,
252+
3B1129262226E5D800B6E06A /* PBXTargetDependency */,
245253
);
246254
name = StaticTests;
247255
productName = StaticTests;
@@ -391,6 +399,11 @@
391399
target = 21826AA91B3F51A100AA9641 /* Static-iOS */;
392400
targetProxy = 363129C51B50354E0024E339 /* PBXContainerItemProxy */;
393401
};
402+
3B1129262226E5D800B6E06A /* PBXTargetDependency */ = {
403+
isa = PBXTargetDependency;
404+
target = 36748D4E1B5034EC0046F207 /* Example */;
405+
targetProxy = 3B1129252226E5D800B6E06A /* PBXContainerItemProxy */;
406+
};
394407
/* End PBXTargetDependency section */
395408

396409
/* Begin PBXVariantGroup section */

Static.xcodeproj/xcshareddata/xcschemes/Example.xcscheme

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@
2828
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
2929
shouldUseLaunchSchemeArgsEnv = "YES">
3030
<Testables>
31+
<TestableReference
32+
skipped = "NO">
33+
<BuildableReference
34+
BuildableIdentifier = "primary"
35+
BlueprintIdentifier = "21826AB31B3F51A100AA9641"
36+
BuildableName = "StaticTests.xctest"
37+
BlueprintName = "StaticTests"
38+
ReferencedContainer = "container:Static.xcodeproj">
39+
</BuildableReference>
40+
</TestableReference>
3141
</Testables>
3242
<MacroExpansion>
3343
<BuildableReference

Static/DataSource.swift

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public class DataSource: NSObject {
101101
refresh()
102102
}
103103

104-
private func refresh(oldSections: [Section]? = nil) {
104+
private func refresh(oldSections: [Section] = []) {
105105
refreshTableSections(oldSections: oldSections)
106106
refreshRegisteredCells()
107107
}
@@ -127,9 +127,9 @@ public class DataSource: NSObject {
127127
return nil
128128
}
129129

130-
private func refreshTableSections(oldSections: [Section]? = nil) {
130+
private func refreshTableSections(oldSections: [Section] = []) {
131131
guard let tableView = tableView else { return }
132-
guard let oldSections = oldSections else {
132+
guard !oldSections.isEmpty else {
133133
tableView.reloadData()
134134
return
135135
}
@@ -151,8 +151,7 @@ public class DataSource: NSObject {
151151
tableView.insertSections(IndexSet(integersIn: range), with: animation)
152152
} else {
153153
// Remove sections
154-
let start = oldCount - 1
155-
let range: Range<IndexSet.Element> = start..<(start - delta)
154+
let range: Range<IndexSet.Element> = newCount..<(newCount - delta)
156155
tableView.deleteSections(IndexSet(integersIn: range), with: animation)
157156
}
158157

Static/Tests/DataSourceTests.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ class DataSourceTests: XCTestCase {
4141
XCTAssertEqual(4, tableView.numberOfRows(inSection: 1))
4242
XCTAssertEqual(2, tableView.numberOfRows(inSection: 2))
4343

44+
dataSource.sections = [
45+
Section(rows: [Row(text: "Merrily"), Row(text: "Merrily")]),
46+
Section(rows: [Row(text: "Life"), Row(text: "Is"), Row(text: "But"), Row(text: "A"), Row(text: "Dream")]),
47+
]
48+
XCTAssertEqual(2, tableView.numberOfSections)
49+
XCTAssertEqual(2, tableView.numberOfRows(inSection: 0))
50+
XCTAssertEqual(5, tableView.numberOfRows(inSection: 1))
51+
4452
dataSource.sections = []
4553
XCTAssertEqual(0, tableView.numberOfSections)
4654
}

0 commit comments

Comments
 (0)