Created
October 11, 2019 05:27
-
-
Save strzempa/82c134a6fd68053c79517b1df5f55dc8 to your computer and use it in GitHub Desktop.
This file contains 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
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