Last active
May 10, 2016 14:23
-
-
Save bmoliveira/c047d4c229e8fd2f944a to your computer and use it in GitHub Desktop.
UICollectionView reusable
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
extension UICollectionView { | |
func registerCell<T: ReusableCell>(cellType: T.Type) { | |
if let identifier = T.reuseIdentifier() { | |
self.registerNib(T.uiNibFromClass(), forCellWithReuseIdentifier: identifier) | |
} | |
} | |
func dequeueReusableCell<T: UICollectionViewCell>(index: Int) -> T { | |
return dequeueReusableCell(NSIndexPath(forItem: index, inSection: 0)) | |
} | |
func dequeueReusableCell<T: UICollectionViewCell>(indexPath: NSIndexPath) -> T { | |
return dequeueReusableCellWithReuseIdentifier(T.className, forIndexPath: indexPath) as? T ?? T() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment