Skip to content

Commit 14816fb

Browse files
committed
adds cell registration extension on CollectionView
1 parent e8533f3 commit 14816fb

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import UIKit
2+
3+
public extension UICollectionView {
4+
5+
/// Registers a class for use in creating new cell items.
6+
///
7+
/// Discussion
8+
9+
/// Prior to dequeueing any cells, call this method or the register(_:forCellReuseIdentifier:) method to tell the collection view how to create new cells. If a cell of the specified type is not currently in a reuse queue, the collection view uses the provided information to create a new cell object automatically.
10+
/// - Parameter type: The class of a cell that you want to use in the table.
11+
func register<T: ReuseIdentifierProviding>(class type: T.Type) where T: UICollectionViewCell {
12+
register(type, forCellWithReuseIdentifier: T.reuseIdentifier)
13+
}
14+
15+
/// Registers a nib object containing a cell with the collection view under a ReuseIdentifierProviding reuse identifier.
16+
///
17+
/// Discussion
18+
19+
/// Prior to dequeueing any cells, call this method or the register(_:forCellReuseIdentifier:) method to tell the collection view how to create new cells. If a cell of the specified type is not currently in a reuse queue, the collection view uses the provided information to create a new cell object automatically.
20+
/// - Parameter nibFor: Uses ReuseIdentifierProvidings reuse identifer to create a nib.
21+
func register<T: ReuseIdentifierProviding>(nibFor type: T.Type) where T: UICollectionViewCell {
22+
let reuseIdentifier = T.reuseIdentifier
23+
let uiNib = UINib(nibName: reuseIdentifier, bundle: Bundle(for: type))
24+
register(uiNib, forCellWithReuseIdentifier: reuseIdentifier)
25+
}
26+
27+
}

0 commit comments

Comments
 (0)