Guest User

Untitled

a guest
Dec 18th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. protocol CollectionViewType {
  2. func register<T: UICollectionViewCell>(_ cellClass: T.Type)
  3. func dequeue<T: UICollectionViewCell>(_ cellClass: T.Type, for indexPath: IndexPath) -> T?
  4. }
  5.  
  6. extension UICollectionView: CollectionViewType {
  7. func register<T: UICollectionViewCell>(_ cellClass: T.Type) {
  8. register(cellClass, forCellWithReuseIdentifier: String(describing: cellClass))
  9. }
  10.  
  11. func dequeue<T: AnyObject>(_ cellClass: T.Type, for indexPath: IndexPath) -> T? {
  12. return dequeueReusableCell(withReuseIdentifier: String(describing: cellClass), for: indexPath) as? T
  13. }
  14. }
  15.  
  16. // USAGE
  17. let cell = collectionView.dequeue(MediaCell.self, for: indexPath)!
Add Comment
Please, Sign In to add comment