Skip to content

Instantly share code, notes, and snippets.

@TsRebornz
Created April 16, 2024 11:45
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 TsRebornz/1ff0aaca6e16864b203e656012f583f4 to your computer and use it in GitHub Desktop.
Save TsRebornz/1ff0aaca6e16864b203e656012f583f4 to your computer and use it in GitHub Desktop.
UICollectionView handy extensions
///
/// Allow you to register cells with code
/// <CellName>.reuseIdentifier
extension UICollectionReusableView {
static var reuseIdentifier: String {
return String(describing: Self.self)
}
}
///
/// Coupled with extension above you could register UICollectionViewCell like this
/// collectionView.register(cell: <CellName>.self)
extension UICollectionView {
func register<T: UICollectionViewCell>(cell: T.Type) {
register(T.self, forCellWithReuseIdentifier: T.reuseIdentifier)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment