Created
April 16, 2024 11:45
-
-
Save TsRebornz/1ff0aaca6e16864b203e656012f583f4 to your computer and use it in GitHub Desktop.
UICollectionView handy extensions
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
/// | |
/// 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