Skip to content

Instantly share code, notes, and snippets.

@bmoliveira
Last active May 10, 2016 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bmoliveira/c047d4c229e8fd2f944a to your computer and use it in GitHub Desktop.
Save bmoliveira/c047d4c229e8fd2f944a to your computer and use it in GitHub Desktop.
UICollectionView reusable
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