Last active
August 9, 2016 12:53
-
-
Save luca-bernardi/6d922e77df4a1a9584b49300df65f9cb 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
protocol Reusable{ | |
static var reuseIdentifier: String { get } | |
} | |
extension Reusable { | |
static var reuseIdentifier: String { return String(Self.self) } | |
} | |
extension UICollectionViewCell : Reusable {} | |
extension UICollectionView { | |
func register<T: UICollectionViewCell where T: Reusable>(_ : T.Type) { | |
register(T.self, forCellWithReuseIdentifier: T.reuseIdentifier) | |
} | |
func dequeue<T: UICollectionViewCell where T:Reusable>(_: T.Type, for indexPath: IndexPath) -> T { | |
return dequeueReusableCell(withReuseIdentifier: T.reuseIdentifier, for: indexPath) as! T; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment