Skip to content

Instantly share code, notes, and snippets.

@heinrisch
Created March 21, 2017 12:05
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 heinrisch/212380d14bb00385681a534b110f0672 to your computer and use it in GitHub Desktop.
Save heinrisch/212380d14bb00385681a534b110f0672 to your computer and use it in GitHub Desktop.
Nicer register class and dequeue
extension UICollectionView {
func dequeueCell<T: UICollectionViewCell>(_ indexPath: IndexPath) -> T {
let reuseIdentifier = T.classForCoder().description()
guard let cell = dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath) as? T else {
fatalError("Could not dequeue cell with identifier \(reuseIdentifier)")
}
return cell
}
func registerClass<T: UICollectionViewCell>(_ type: T.Type) {
register(T.classForCoder(), forCellWithReuseIdentifier: T.classForCoder().description())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment