Skip to content

Instantly share code, notes, and snippets.

@krodak
Last active March 17, 2016 16:46
Show Gist options
  • Save krodak/25680b1ec18e750f6ddd to your computer and use it in GitHub Desktop.
Save krodak/25680b1ec18e750f6ddd to your computer and use it in GitHub Desktop.
UICollectionView+dequeue
extension UICollectionView {
public func dequeueReusableCell<T:UICollectionViewCell>(type: T.Type, indexPath: NSIndexPath) -> T {
let collectionCell : T
let cellIdentifier = String(T)
if let _ = NSBundle(forClass: T.classForCoder()).pathForResource(cellIdentifier, ofType:"nib") {
registerNib(UINib(nibName: cellIdentifier, bundle: nil), forCellWithReuseIdentifier: cellIdentifier)
collectionCell = dequeueReusableCellWithReuseIdentifier(cellIdentifier, forIndexPath: indexPath) as! T
}
else {
collectionCell = T()
}
return collectionCell
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment