File tree Expand file tree Collapse file tree 3 files changed +99
-1
lines changed Expand file tree Collapse file tree 3 files changed +99
-1
lines changed Original file line number Diff line number Diff line change @@ -200,7 +200,7 @@ Check if all UITableViewCells available through the UITableView data source eval
200
200
``` Swift
201
201
// Create an enumerate closure
202
202
let doesFitClosure: (UITableViewCell)-> Bool = { (cell) -> Bool in
203
- guard let cell = cell as? TableViewCell else {
203
+ guard let cell = cell as? CustomTableViewCell else {
204
204
return false
205
205
}
206
206
if cell.customLabel.text ? .characters .count == 0 {
@@ -218,6 +218,30 @@ You can also ask for an array of IndexPaths that don't fit the criteria
218
218
let indexPaths: [IndexPath] = subject.tableView .spec .check .allCells (thatDontFit : doesFitClosure)
219
219
```
220
220
221
+ #### Checking collection view cells
222
+
223
+ Check if all UICollectionViewCell available through the UICollectionView data source evaluate correctly
224
+ ``` Swift
225
+ // Create an enumerate closure
226
+ let doesFitClosure: (UICollectionViewCell)-> Bool = { (cell) -> Bool in
227
+ guard let cell = cell as? CustomCollectionViewCell else {
228
+ return false
229
+ }
230
+ if cell.customLabel.text ? .characters .count == 0 {
231
+ return false
232
+ }
233
+ return true
234
+ }
235
+
236
+ // Test if all cells generated by the data source are ok using your closure
237
+ let ok = subject.collectionView .spec .check .allCells (fit : doesFitClosure)
238
+ ```
239
+
240
+ You can also ask for an array of IndexPaths that don't fit the criteria
241
+ ``` Swift
242
+ let indexPaths: [IndexPath] = subject.collectionView .spec .check .allCells (thatDontFit : doesFitClosure)
243
+ ```
244
+
221
245
#### UIViewController checks
222
246
223
247
Look for a specific view controller in your navigation stack
Original file line number Diff line number Diff line change
1
+ //
2
+ // Checks+UICollectionView.swift
3
+ // SpecTools
4
+ //
5
+ // Created by Ondrej Rafaj on 15/09/2017.
6
+ //
7
+
8
+ import Foundation
9
+ import UIKit
10
+
11
+
12
+ extension Check where T: UICollectionView {
13
+
14
+ // MARK: UICollectionView
15
+
16
+ /// Check if there are any cells that don't fit criteria specified in a closure
17
+ /// - Parameter fit: Closure that needs to evaluate the cell which is passed onto it
18
+ /// - Returns: Bool (true if no issue is found)
19
+ public func allCells( fit evaluateClosure: ( UICollectionViewCell ) -> Bool ) -> Bool {
20
+ return allCells ( thatDontFit: evaluateClosure) . count == 0
21
+ }
22
+
23
+ /// Check if there are any cells that don't fit criteria specified in a closure
24
+ /// - Parameter fit: Closure that needs to evaluate the cell which is passed onto it
25
+ /// - Returns: [IndexPath] Index path of all cells that do not match the given criteria
26
+ public func allCells( thatDontFit evaluateClosure: ( UICollectionViewCell ) -> Bool ) -> [ IndexPath ] {
27
+ var indexPaths : [ IndexPath ] = [ ]
28
+ for sectionIndex in 0 ... element. spec. find. numberOfSections ( ) {
29
+ row: for rowIndex in 0 ... element. spec. find. number ( ofRowsIn: sectionIndex) {
30
+ let indexPath = IndexPath ( item: rowIndex, section: sectionIndex)
31
+ guard let cell = element. dataSource? . collectionView ( element, cellForItemAt: indexPath) else {
32
+ fatalError ( " Data source is not set " )
33
+ }
34
+
35
+ let ok = evaluateClosure ( cell)
36
+ if !ok {
37
+ indexPaths. append ( indexPath)
38
+ }
39
+ }
40
+ }
41
+ return indexPaths
42
+ }
43
+
44
+ }
45
+
Original file line number Diff line number Diff line change
1
+ //
2
+ // Find+UICollectionView.swift
3
+ // SpecTools
4
+ //
5
+ // Created by Ondrej Rafaj on 15/09/2017.
6
+ //
7
+
8
+ import Foundation
9
+ import UIKit
10
+
11
+
12
+ extension Find where T: UICollectionView {
13
+
14
+ // MARK: UICollectionView
15
+
16
+ /// Return number of sections on a collection view data source
17
+ /// - Returns: Int
18
+ public func numberOfSections( ) -> Int {
19
+ return element. dataSource? . numberOfSections ? ( in: element) ?? 0
20
+ }
21
+
22
+ /// Number of rows on a section in a collection view data source
23
+ /// - Parameter ofRowsIn: Section index
24
+ /// - Returns: Int
25
+ public func number( ofRowsIn section: Int ) -> Int {
26
+ return element. dataSource? . collectionView ( element, numberOfItemsInSection: section) ?? 0
27
+ }
28
+
29
+ }
You can’t perform that action at this time.
0 commit comments