Created
March 19, 2015 19:07
-
-
Save justinmakaila/18971b5aa3ce9d955d82 to your computer and use it in GitHub Desktop.
UICollectionView+NibView
This file contains hidden or 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 | |
| extension UICollectionView { | |
| // MARK: - Dequeue Nib Views | |
| func dequeueNibView<T: UICollectionViewCell where T: ReuseIdentifierProtocol>(view: T.Type, indexPath: NSIndexPath) -> T { | |
| return dequeueReusableCellWithReuseIdentifier(view.reuseIdentifier(), forIndexPath: indexPath) as T | |
| } | |
| func dequeueSupplementaryReusableNibView<T: UICollectionReusableView where T: ReuseIdentifierProtocol>(view: T.Type, kind: String, indexPath: NSIndexPath) -> T { | |
| return dequeueReusableSupplementaryViewOfKind(kind, withReuseIdentifier: view.reuseIdentifier(), forIndexPath: indexPath) as T | |
| } | |
| func dequeueReusableNibViewKind<T: UICollectionReusableView where T: ReusableNibViewKind>(view: T.Type, indexPath: NSIndexPath) -> T { | |
| return dequeueSupplementaryReusableNibView(view, kind: view.reusableKind(), indexPath: indexPath) | |
| } | |
| // MARK: - Register Nib Views | |
| func registerNibView<T: UICollectionViewCell where T: CellNibView>(view: T.Type) { | |
| registerNibView(view, reuseIdentifier: view.reuseIdentifier()) | |
| } | |
| func registerNibView<T: UICollectionViewCell where T: NibView>(view: T.Type, reuseIdentifier: String) { | |
| registerNib(view.nib(), forCellWithReuseIdentifier: reuseIdentifier) | |
| } | |
| func registerReusableNibView<T: UICollectionReusableView where T: ReusableNibView>(view: T.Type, kind: String) { | |
| registerReusableNibView(view, kind: kind, reuseIdentifier: view.reuseIdentifier()) | |
| } | |
| func registerReusableNibView<T: UICollectionReusableView where T: NibView>(view: T.Type, kind: String, reuseIdentifier: String) { | |
| registerNib(view.nib(), forSupplementaryViewOfKind: kind, withReuseIdentifier: reuseIdentifier) | |
| } | |
| func registerReusableNibView<T: UICollectionReusableView where T: ReusableNibViewKind>(view: T.Type) { | |
| registerReusableNibView(view, kind: view.reusableKind()) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment