So I created a custom an abstract class who inherit from UIViewController (Inherited by RebloodViewController) class named MainViewController. In this class I write a reusable nib registration function
class MainViewController: RebloodViewController {
typealias Cell = RebloodViewController.Constants.Cell
internal func registerNib(_ cellNib: Cell.Nib, target: UICollectionView) {
let nib = UINib(nibName: cellNib.rawValue, bundle: nil)
do {
let identifier = try getCellIdentifierByNib(cellNib)
target.register(nib, forCellWithReuseIdentifier: identifier)
} catch {
fatalError("Cell identifier not found from given nib")
}
}
private func getCellIdentifierByNib(_ nib: Cell.Nib) throws -> String {
var identifier: String? = nil
switch nib {
case .articles:
identifier = Cell.Identifier.articles.rawValue
case .events:
identifier = Cell.Identifier.events.rawValue
}
guard let CellIdentifier = identifier else {
throw MainError.cellIdentifierNotFound
}
return CellIdentifier
}
}
What is the best way to unit test these private and internal function? Because I can't access the functions from the test files.