Skip to content

Instantly share code, notes, and snippets.

@dtorres
Created June 15, 2016 10:47
Show Gist options
  • Save dtorres/514edceb72e3d81cb4530d4db7715610 to your computer and use it in GitHub Desktop.
Save dtorres/514edceb72e3d81cb4530d4db7715610 to your computer and use it in GitHub Desktop.
protocol reuseIdentifierClass {
static var reuseIdentifier: String { get }
}
extension UICollectionView {
func registerClass<T: UICollectionViewCell where T: reuseIdentifierClass>(aClass: T.Type) {
registerClass(aClass, forCellWithReuseIdentifier: aClass.reuseIdentifier)
}
func dequeueReusableCellWithClass<T: UICollectionViewCell where T: reuseIdentifierClass>(aClass: T.Type, forIndexPath indexPath: NSIndexPath) -> T {
return dequeueReusableCellWithReuseIdentifier(aClass.reuseIdentifier, forIndexPath: indexPath) as! T
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment