Skip to content

Commit d504366

Browse files
committed
Reduce force unwraps
1 parent 1defdf4 commit d504366

1 file changed

Lines changed: 18 additions & 6 deletions

File tree

GLTableCollectionViewTests/GLTableCollectionViewTests.swift

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,16 +93,20 @@ final class GLTableCollectionViewTests: XCTestCase {
9393
func testUITableViewCellClasses() {
9494
XCTAssertGreaterThan(visibleCells.count, 0, "UITableView visible cells must be greater than 0")
9595

96-
for tableViewCell in visibleCells {
97-
XCTAssertTrue(tableViewCell is GLCollectionTableViewCell, "UITableViewCells must be GLCollectionTableViewCell")
96+
visibleCells.forEach { cell in
97+
if cell is GLCollectionTableViewCell {
98+
return
99+
} else {
100+
XCTAssertTrue(cell is GLCollectionTableViewCell, "UITableViewCells must be GLCollectionTableViewCell")
101+
}
98102
}
99103
}
100104

101105
func testTableViewCellIdentifiers() {
102106
XCTAssertGreaterThan(visibleCells.count, 0, "UITableView visible cells must be greater than 0")
103107

104108
visibleCells.forEach { cell in
105-
guard let tableViewCell = cell as? GLCollectionTableViewCell else {
109+
guard let tableViewCell: GLCollectionTableViewCell = cell as? GLCollectionTableViewCell else {
106110
fatalError("UITableViewCells must be GLCollectionTableViewCell")
107111
}
108112

@@ -121,7 +125,7 @@ final class GLTableCollectionViewTests: XCTestCase {
121125
XCTAssertGreaterThan(visibleCells.count, 0, "UITableView visible cells must be greater than 0")
122126

123127
visibleCells.forEach { cell in
124-
guard let collectionTableCell = cell as? GLCollectionTableViewCell else {
128+
guard let collectionTableCell: GLCollectionTableViewCell = cell as? GLCollectionTableViewCell else {
125129
fatalError("UITableViewCells must be GLCollectionTableViewCell")
126130
}
127131

@@ -133,7 +137,11 @@ final class GLTableCollectionViewTests: XCTestCase {
133137
func testCollectionNativePaginationFlag() {
134138
XCTAssertGreaterThan(visibleCells.count, 0, "UITableView visible cells must be greater than 0")
135139

136-
for collectionTableCell: GLCollectionTableViewCell in visibleCells as! [GLCollectionTableViewCell] {
140+
visibleCells.forEach { cell in
141+
guard let collectionTableCell: GLCollectionTableViewCell = cell as? GLCollectionTableViewCell else {
142+
fatalError("UITableViewCells must be GLCollectionTableViewCell")
143+
}
144+
137145
if collectionTableCell.collectionViewPaginatedScroll == true {
138146
XCTAssertFalse(collectionTableCell.collectionView.isPagingEnabled,
139147
"Custom scrolling pagination and native UICollectionView pagination can't be enabled at the same time")
@@ -171,7 +179,11 @@ final class GLTableCollectionViewTests: XCTestCase {
171179

172180
XCTAssertGreaterThan(visibleCells.count, 0, "UITableView visible cells must be greater than 0")
173181

174-
for collectionTableCell: GLCollectionTableViewCell in visibleCells as! [GLCollectionTableViewCell] {
182+
visibleCells.forEach { cell in
183+
guard let collectionTableCell: GLCollectionTableViewCell = cell as? GLCollectionTableViewCell else {
184+
fatalError("UITableViewCells must be GLCollectionTableViewCell")
185+
}
186+
175187
XCTAssertTrue(collectionTableCell.collectionView.isOpaque, "The UICollectionView should be opaque for increased performances")
176188
}
177189
}

0 commit comments

Comments
 (0)