This library allows you to specify a custom UIKit view as reusable, providing simple shorthand and type-safety for common types like UICollectionViewCell, UITableViewCell, and other views which can be loaded from a storyboard or nib.
- In Xcode, select File > Swift Packages > Add Package Dependency.
- Follow the prompts using the URL for this repository.
class CustomTableViewCell: UITableViewCell, UIReusableView { }
class CustomCollectionViewCell: UICollectionViewCell, UIReusableView { }
override func viewDidLoad() {
super.viewDidLoad()
CustomTableViewCell.register(in: tableView)
}
override func viewDidLoad() {
super.viewDidLoad()
CustomCollectionViewCell.register(in: collectionView)
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell: CustomTableViewCell = .dequeue(from: tableView, at: indexPath)
return cell
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell: CustomCollectionViewCell = .dequeue(from: collectionView, at: indexPath)
return cell
}