-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add automatically computed reuse identifier feature for CollectionVie…
…wCell and TableViewCell (#15) * [AddReuseIdentifiersForTableAndCollectionViewCells] - Finish implementation * [AddReuseIdentifiersForTableAndCollectionViewCells] - Add unit tests and improve implementation
- Loading branch information
1 parent
fffe11a
commit 34d7b60
Showing
6 changed files
with
153 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// | ||
// UICollectionViewCell+Additions.swift | ||
// FCExtensionKit | ||
// | ||
// Created by Erinç Olkan Dokumacıoğlu on 22.04.2022. | ||
// | ||
|
||
import UIKit | ||
|
||
extension UICollectionViewCell { | ||
/// Automatically changes reuse identifier property of an xib designed cell. | ||
open override var reuseIdentifier: String { | ||
return String(describing: Self.self) | ||
} | ||
|
||
/// Creates a static reuse identifier for collection view cell using its class name. | ||
public static var reuseIdentifier: String { | ||
return String(describing: Self.self) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// | ||
// UITableViewCell+Additions.swift | ||
// FCExtensionKit | ||
// | ||
// Created by Erinç Olkan Dokumacıoğlu on 22.04.2022. | ||
// | ||
|
||
import UIKit | ||
|
||
public extension UITableViewCell { | ||
/// Creates a static reuse identifier for table view cell using its class name. | ||
/// | ||
/// - Warning: If you are using xib files for your cell design, you are obliged to manually assign a reuse identifier for your cell in the Interface Builder. | ||
static var reuseIdentifier: String { | ||
return String(describing: self) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// | ||
// UICollectionViewCell+AdditionsTests.swift | ||
// FCExtensionKitTests | ||
// | ||
// Created by Erinç Olkan Dokumacıoğlu on 22.04.2022. | ||
// | ||
|
||
import XCTest | ||
import UIKit | ||
@testable import FCExtensionKit | ||
|
||
class UICollectionViewCell_AdditionsTests: XCTestCase { | ||
var collectionView: UICollectionView! | ||
|
||
override func setUp() { | ||
super.setUp() | ||
|
||
let layout = UICollectionViewLayout() | ||
collectionView = UICollectionView(frame: .zero, collectionViewLayout: layout) | ||
collectionView.register(FakeCollectionViewCell.self, forCellWithReuseIdentifier: FakeCollectionViewCell.reuseIdentifier) | ||
} | ||
|
||
func testCanDequeueCellUsingInstanceVariableReuseIdentifier() { | ||
let cellInstance = FakeCollectionViewCell() | ||
let dequeuedCell = collectionView.dequeueReusableCell(withReuseIdentifier: cellInstance.reuseIdentifier, for: IndexPath(row: 0, section: 0)) as? FakeCollectionViewCell | ||
|
||
XCTAssertNotNil(dequeuedCell) | ||
XCTAssertEqual(dequeuedCell?.reuseIdentifier, FakeCollectionViewCell.reuseIdentifier) | ||
} | ||
|
||
func testCanDequeueCellUsingStaticReuseIdentifier() { | ||
let dequeuedCell = collectionView.dequeueReusableCell(withReuseIdentifier: FakeCollectionViewCell.reuseIdentifier, for: IndexPath(row: 0, section: 0)) as? FakeCollectionViewCell | ||
|
||
XCTAssertNotNil(dequeuedCell) | ||
XCTAssertEqual(dequeuedCell?.reuseIdentifier, FakeCollectionViewCell.reuseIdentifier) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// | ||
// UITableViewCell+AdditionsTests.swift | ||
// FCExtensionKitTests | ||
// | ||
// Created by Erinç Olkan Dokumacıoğlu on 22.04.2022. | ||
// | ||
|
||
import XCTest | ||
import UIKit | ||
@testable import FCExtensionKit | ||
|
||
class UITableViewCell_AdditionsTests: XCTestCase { | ||
var tableView: UITableView! | ||
|
||
override func setUp() { | ||
super.setUp() | ||
|
||
tableView = UITableView() | ||
tableView.register(FakeTableViewCell.self, forCellReuseIdentifier: FakeTableViewCell.reuseIdentifier) | ||
} | ||
|
||
func testCanDequeueCellUsingReuseIdentifier() { | ||
let cell = tableView.dequeueReusableCell(withIdentifier: FakeTableViewCell.reuseIdentifier) as? FakeTableViewCell | ||
|
||
XCTAssertNotNil(cell) | ||
XCTAssertEqual(cell?.reuseIdentifier, FakeTableViewCell.reuseIdentifier) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// | ||
// FakeCellClasses.swift | ||
// FCExtensionKitTests | ||
// | ||
// Created by Erinç Olkan Dokumacıoğlu on 22.04.2022. | ||
// | ||
|
||
import UIKit | ||
import FCExtensionKit | ||
|
||
class FakeCollectionViewCell: UICollectionViewCell { | ||
|
||
} | ||
|
||
class FakeTableViewCell: UITableViewCell { | ||
override init(style: UITableViewCell.CellStyle = .default, reuseIdentifier: String?) { | ||
super.init(style: style, reuseIdentifier: reuseIdentifier) | ||
} | ||
|
||
required init?(coder: NSCoder) { | ||
fatalError("init(coder:) has not been implemented") | ||
} | ||
} |