Skip to content

Instantly share code, notes, and snippets.

@strzempa
Created October 11, 2019 05:27
Show Gist options
  • Save strzempa/82c134a6fd68053c79517b1df5f55dc8 to your computer and use it in GitHub Desktop.
Save strzempa/82c134a6fd68053c79517b1df5f55dc8 to your computer and use it in GitHub Desktop.
import UIKit
public protocol UICollectionViewCellIdentifiable: UICollectionViewCell {
static var identifier: String { get }
}
public extension UICollectionViewCellIdentifiable where Self: UICollectionViewCell {
static var identifier: String {
return String(describing: self)
}
}
public extension UICollectionView {
func register(_ cells: [UICollectionViewCellIdentifiable.Type]) {
cells.forEach { cell in
self.register(cell.self, forCellWithReuseIdentifier: cell.identifier)
self.register(UINib(nibName: cell.identifier, bundle: nil), forCellWithReuseIdentifier: cell.identifier)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment