Created
March 21, 2017 12:05
-
-
Save heinrisch/212380d14bb00385681a534b110f0672 to your computer and use it in GitHub Desktop.
Nicer register class and dequeue
This file contains hidden or 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 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