Last active
December 15, 2017 10:45
-
-
Save nahive/5dbc93cd0afb6bfff929b88ef5192f36 to your computer and use it in GitHub Desktop.
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
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)! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment