Last active
May 8, 2019 00:59
-
-
Save jeanetienne/5e93609a05a2773ba6efd5ca8f430f33 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// | |
// More type-aware convenience functions for registering and dequeueing cells | |
// | |
import UIKit | |
fileprivate extension UICollectionViewCell { | |
static var defaultReuseIdentifier: String { | |
return String(describing: self) | |
} | |
} | |
extension UICollectionView { | |
func register<Cell: UICollectionViewCell>(_ cellType: Cell.Type) { | |
register(cellType, forCellWithReuseIdentifier: cellType.defaultReuseIdentifier) | |
} | |
func dequeue<Cell: UICollectionViewCell>(_ cellType: Cell.Type, for indexPath: IndexPath) -> Cell? { | |
return dequeueReusableCell(withReuseIdentifier: cellType.defaultReuseIdentifier, for: indexPath) as? Cell | |
} | |
} | |
fileprivate extension UITableViewCell { | |
static var defaultReuseIdentifier: String { | |
return String(describing: self) | |
} | |
} | |
extension UITableView { | |
func register<Cell: UITableViewCell>(_ cellType: Cell.Type) { | |
register(cellType, forCellReuseIdentifier: cellType.defaultReuseIdentifier) | |
} | |
func dequeue<Cell: UITableViewCell>(_ cellType: Cell.Type, for indexPath: IndexPath) -> Cell? { | |
return dequeueReusableCell(withIdentifier: cellType.defaultReuseIdentifier, for: indexPath) as? Cell | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment