Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- protocol CollectionViewType {
- func register<T: UICollectionViewCell>(_ cellClass: T.Type)
- func dequeue<T: UICollectionViewCell>(_ cellClass: T.Type, for indexPath: IndexPath) -> T?
- }
- extension UICollectionView: CollectionViewType {
- func register<T: UICollectionViewCell>(_ cellClass: T.Type) {
- register(cellClass, forCellWithReuseIdentifier: String(describing: cellClass))
- }
- func dequeue<T: AnyObject>(_ cellClass: T.Type, for indexPath: IndexPath) -> T? {
- return dequeueReusableCell(withReuseIdentifier: String(describing: cellClass), for: indexPath) as? T
- }
- }
- // USAGE
- let cell = collectionView.dequeue(MediaCell.self, for: indexPath)!
Add Comment
Please, Sign In to add comment