Skip to content

Commit 184eb60

Browse files
committed
Adjust var visibility + UICollectionViewCell identifier isolation
1 parent 67cf34d commit 184eb60

4 files changed

Lines changed: 20 additions & 18 deletions

File tree

Classes/GLCollectionTableViewCell.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ class GLCollectionTableViewCell: UITableViewCell {
160160
collectionFlowLayout.scrollDirection = .horizontal
161161

162162
collectionView = GLIndexedCollectionView(frame: .zero, collectionViewLayout: collectionFlowLayout)
163-
collectionView.register(UINib(nibName: "GLIndexedCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "collectionViewCellID")
163+
collectionView.register(UINib(nibName: "GLIndexedCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: GLIndexedCollectionViewCell.identifier)
164164
collectionView.backgroundColor = .white
165165
collectionView.showsHorizontalScrollIndicator = false
166166
collectionView.showsVerticalScrollIndicator = false

Classes/GLIndexedCollectionViewCell.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
import UIKit
3131

3232
class GLIndexedCollectionViewCell: UICollectionViewCell {
33+
static let identifier: String = "collectionViewCellID"
34+
3335
override func awakeFromNib() {
3436
super.awakeFromNib()
3537
// Initialization code

Classes/GLTableCollectionViewController.swift

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,23 @@
2929

3030
import UIKit
3131

32-
class GLTableCollectionViewController: UITableViewController, UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout {
33-
// This string constant will be the cellIdentifier for the UITableViewCells
34-
// holding the UICollectionView, it's important to append "_section#" to it
35-
// so we can understand which cell is the one we are looking for in the
36-
// debugger. Look in UITableView's data source cellForRowAt method for more
37-
// explanations about the UITableViewCell reuse handling.
38-
let tableCellID: String = "tableViewCellID_section_#"
39-
let collectionCellID: String = "collectionViewCellID"
32+
final class GLTableCollectionViewController: UITableViewController, UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout {
33+
// This static string constant will be the cellIdentifier for the
34+
// UITableViewCells holding the UICollectionView, it's important to append
35+
// "_section#" to it so we can understand which cell is the one we are
36+
// looking for in the debugger. Look in UITableView's data source
37+
// cellForRowAt method for more explanations about the UITableViewCell reuse
38+
// handling.
39+
private static let tableCellID: String = "tableViewCellID_section_#"
4040

41-
let numberOfSections: Int = 20
42-
let numberOfCollectionsForRow: Int = 1
43-
let numberOfCollectionItems: Int = 20
41+
private let numberOfSections: Int = 20
42+
private let numberOfCollectionsForRow: Int = 1
43+
private let numberOfCollectionItems: Int = 20
4444

45-
var colorsDict: [Int: [UIColor]] = [:]
45+
private var colorsDict: [Int: [UIColor]] = [:]
4646

4747
/// Set true to enable UICollectionViews scroll pagination
48-
var paginationEnabled: Bool = true
48+
private var paginationEnabled: Bool = true
4949

5050
override func viewDidLoad() {
5151
super.viewDidLoad()
@@ -109,10 +109,10 @@ class GLTableCollectionViewController: UITableViewController, UICollectionViewDa
109109
// will have a different UICollectionView with UICollectionViewCells in
110110
// it and UITableView reuse won't work as expected giving back wrong
111111
// cells.
112-
var cell: GLCollectionTableViewCell? = tableView.dequeueReusableCell(withIdentifier: tableCellID + indexPath.section.description) as? GLCollectionTableViewCell
112+
var cell: GLCollectionTableViewCell? = tableView.dequeueReusableCell(withIdentifier: GLTableCollectionViewController.tableCellID + indexPath.section.description) as? GLCollectionTableViewCell
113113

114114
if cell == nil {
115-
cell = GLCollectionTableViewCell(style: .default, reuseIdentifier: tableCellID + indexPath.section.description)
115+
cell = GLCollectionTableViewCell(style: .default, reuseIdentifier: GLTableCollectionViewController.tableCellID + indexPath.section.description)
116116

117117
// Configure the cell...
118118
cell!.selectionStyle = .none
@@ -159,7 +159,7 @@ class GLTableCollectionViewController: UITableViewController, UICollectionViewDa
159159
}
160160

161161
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
162-
guard let cell: GLIndexedCollectionViewCell = collectionView.dequeueReusableCell(withReuseIdentifier: collectionCellID, for: indexPath) as? GLIndexedCollectionViewCell else {
162+
guard let cell: GLIndexedCollectionViewCell = collectionView.dequeueReusableCell(withReuseIdentifier: GLIndexedCollectionViewCell.identifier, for: indexPath) as? GLIndexedCollectionViewCell else {
163163
fatalError("UICollectionViewCell must be of GLIndexedCollectionViewCell type")
164164
}
165165

GLTableCollectionView/AppDelegate.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
import UIKit
3131

3232
@UIApplicationMain
33-
class AppDelegate: UIResponder, UIApplicationDelegate {
33+
final class AppDelegate: UIResponder, UIApplicationDelegate {
3434
var window: UIWindow?
3535

3636
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

0 commit comments

Comments
 (0)