Skip to content

Commit fd0ce43

Browse files
committed
Changelog + clean up + linter fixes from #119
1 parent b0c94f0 commit fd0ce43

File tree

4 files changed

+35
-29
lines changed

4 files changed

+35
-29
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ NEXT
77

88
- TBA
99

10+
0.1.3
11+
-----
12+
13+
- Improve debug descriptions for `CollectionViewModel` and `SectionViewModel` ([@nuomi1](https://github.com/nuomi1), [#119](https://github.com/jessesquires/ReactiveCollectionsKit/pull/119))
14+
1015
0.1.2
1116
-----
1217

Sources/CollectionViewModel.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ extension CollectionViewModel: CustomDebugStringConvertible {
262262
/// :nodoc:
263263
nonisolated public var debugDescription: String {
264264
MainActor.assumeIsolated {
265-
ReactiveCollectionsKit.debugDescription(for: self)
265+
collectionDebugDescription(self)
266266
}
267267
}
268268
}

Sources/DebugDescriptions.swift

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -27,70 +27,71 @@ private enum Element {
2727
case end
2828
}
2929

30-
private func print<Target: TextOutputStream>(
30+
private func buildString<Target: TextOutputStream>(
3131
_ text: String,
3232
indent: Int,
3333
to output: inout Target
3434
) {
35-
Swift.print("\(String(repeating: " ", count: indent))\(text)", to: &output)
35+
print("\(String(repeating: " ", count: indent))\(text)", to: &output)
3636
}
3737

38+
// swiftlint:disable:next cyclomatic_complexity
3839
private func debugDescriptionBuilder<Target: TextOutputStream>(
3940
elements: [(Element, Int)],
4041
to output: inout Target
4142
) {
4243
for (element, indent) in elements {
4344
switch element {
4445
case let .type(type):
45-
print("<\(type):", indent: indent, to: &output)
46+
buildString("<\(type):", indent: indent, to: &output)
4647

4748
case let .index(index):
48-
print("[\(index)]:", indent: indent, to: &output)
49+
buildString("[\(index)]:", indent: indent, to: &output)
4950

5051
case let .id(id):
51-
print("id: \(id)", indent: indent, to: &output)
52+
buildString("id: \(id)", indent: indent, to: &output)
5253

5354
case let .header(header):
5455
if let header {
55-
print("header: \(header.id) (\(header.reuseIdentifier))", indent: indent, to: &output)
56+
buildString("header: \(header.id) (\(header.reuseIdentifier))", indent: indent, to: &output)
5657
} else {
57-
print("header: nil", indent: indent, to: &output)
58+
buildString("header: nil", indent: indent, to: &output)
5859
}
5960

6061
case let .footer(footer):
6162
if let footer {
62-
print("footer: \(footer.id) (\(footer.reuseIdentifier))", indent: indent, to: &output)
63+
buildString("footer: \(footer.id) (\(footer.reuseIdentifier))", indent: indent, to: &output)
6364
} else {
64-
print("footer: nil", indent: indent, to: &output)
65+
buildString("footer: nil", indent: indent, to: &output)
6566
}
6667

6768
case let .cells(cells):
6869
if !cells.isEmpty {
69-
print("cells:", indent: indent, to: &output)
70+
buildString("cells:", indent: indent, to: &output)
7071
} else {
71-
print("cells: none", indent: indent, to: &output)
72+
buildString("cells: none", indent: indent, to: &output)
7273
}
7374

7475
for (index, cell) in cells.enumerated() {
75-
print("[\(index)]: \(cell.id) (\(cell.reuseIdentifier))", indent: indent + 2, to: &output)
76+
buildString("[\(index)]: \(cell.id) (\(cell.reuseIdentifier))", indent: indent + 2, to: &output)
7677
}
7778

7879
case let .supplementaryViews(supplementaryViews):
7980
if !supplementaryViews.isEmpty {
80-
print("supplementary views:", indent: indent, to: &output)
81+
buildString("supplementary views:", indent: indent, to: &output)
8182
} else {
82-
print("supplementary views: none", indent: indent, to: &output)
83+
buildString("supplementary views: none", indent: indent, to: &output)
8384
}
8485

8586
for (index, supplementaryView) in supplementaryViews.enumerated() {
86-
print("[\(index)]: \(supplementaryView.id) (\(supplementaryView.reuseIdentifier))", indent: indent + 2, to: &output)
87+
buildString("[\(index)]: \(supplementaryView.id) (\(supplementaryView.reuseIdentifier))", indent: indent + 2, to: &output)
8788
}
8889

8990
case let .sections(sections):
9091
if !sections.isEmpty {
91-
print("sections:", indent: indent, to: &output)
92+
buildString("sections:", indent: indent, to: &output)
9293
} else {
93-
print("sections: none", indent: indent, to: &output)
94+
buildString("sections: none", indent: indent, to: &output)
9495
}
9596

9697
for (index, section) in sections.enumerated() {
@@ -102,34 +103,34 @@ private func debugDescriptionBuilder<Target: TextOutputStream>(
102103
(.footer(section.footer), indent + 4),
103104
(.cells(section.cells), indent + 4),
104105
(.supplementaryViews(section.supplementaryViews), indent + 4),
105-
(.isEmpty(section.isEmpty), indent + 4),
106+
(.isEmpty(section.isEmpty), indent + 4)
106107
],
107108
to: &output
108109
)
109110
}
110111

111112
case let .registrations(registrations):
112113
if !registrations.isEmpty {
113-
print("registrations:", indent: indent, to: &output)
114+
buildString("registrations:", indent: indent, to: &output)
114115
} else {
115-
print("registrations: none", indent: indent, to: &output)
116+
buildString("registrations: none", indent: indent, to: &output)
116117
}
117118

118119
for registration in registrations.sorted(by: { $0.reuseIdentifier < $1.reuseIdentifier }) {
119-
print("- \(registration.reuseIdentifier) (\(registration.viewType.kind))", indent: indent + 2, to: &output)
120+
buildString("- \(registration.reuseIdentifier) (\(registration.viewType.kind))", indent: indent + 2, to: &output)
120121
}
121122

122123
case let .isEmpty(isEmpty):
123-
print("isEmpty: \(isEmpty)", indent: indent, to: &output)
124+
buildString("isEmpty: \(isEmpty)", indent: indent, to: &output)
124125

125126
case .end:
126-
print(">", indent: indent, to: &output)
127+
buildString(">", indent: indent, to: &output)
127128
}
128129
}
129130
}
130131

131132
@MainActor
132-
func debugDescription(for collection: CollectionViewModel) -> String {
133+
func collectionDebugDescription(_ collection: CollectionViewModel) -> String {
133134
var output = ""
134135
debugDescriptionBuilder(
135136
elements: [
@@ -138,15 +139,15 @@ func debugDescription(for collection: CollectionViewModel) -> String {
138139
(.sections(collection.sections), 2),
139140
(.registrations(collection.allRegistrations()), 2),
140141
(.isEmpty(collection.isEmpty), 2),
141-
(.end, 0),
142+
(.end, 0)
142143
],
143144
to: &output
144145
)
145146
return output
146147
}
147148

148149
@MainActor
149-
func debugDescription(for section: SectionViewModel) -> String {
150+
func sectionDebugDescription(_ section: SectionViewModel) -> String {
150151
var output = ""
151152
debugDescriptionBuilder(
152153
elements: [
@@ -158,7 +159,7 @@ func debugDescription(for section: SectionViewModel) -> String {
158159
(.supplementaryViews(section.supplementaryViews), 2),
159160
(.registrations(section.allRegistrations()), 2),
160161
(.isEmpty(section.isEmpty), 2),
161-
(.end, 0),
162+
(.end, 0)
162163
],
163164
to: &output
164165
)

Sources/SectionViewModel.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ extension SectionViewModel: CustomDebugStringConvertible {
299299
/// :nodoc:
300300
nonisolated public var debugDescription: String {
301301
MainActor.assumeIsolated {
302-
ReactiveCollectionsKit.debugDescription(for: self)
302+
sectionDebugDescription(self)
303303
}
304304
}
305305
}

0 commit comments

Comments
 (0)