IGListCollectionContext typesafe method for dequeueReusableCell(withNibName:

Summary: add typesafe method for dequeueReusableCell(withNibName:

Reviewed By: natestedman

Differential Revision: D26266979

fbshipit-source-id: 31297d1563d6c4b931c34ac57911dedc4776310f
This commit is contained in:
Vivian Phung 2021-02-05 09:34:26 -08:00 committed by Facebook GitHub Bot
parent 493f640e4f
commit 7b26f4f32e
2 changed files with 34 additions and 2 deletions

View file

@ -178,7 +178,7 @@ NS_SWIFT_NAME(ListCollectionContext)
@return A cell dequeued from the reuse pool or a newly created one.
@note This method uses a string representation of the cell class as the identifier.
@note This method uses the nib name as the reuse identifier.
*/
- (__kindof UICollectionViewCell *)dequeueReusableCellWithNibName:(NSString *)nibName
bundle:(nullable NSBundle *)bundle

View file

@ -53,11 +53,43 @@ extension ListCollectionContext {
) -> T {
guard let cell = self.dequeueReusableCell(
of: T.self,
for: sectionController, at: index
for: sectionController,
at: index
) as? T else {
fatalError()
}
return cell
}
/**
Dequeues a cell from the collection view reuse pool.
- Parameters:
- nibName: The name of the nib file.
- bundle: The bundle in which to search for the nib file. If `nil`, this method searches the main bundle.
- sectionController: The section controller requesting this information.
- index: The index of the cell.
- Returns: A cell dequeued from the reuse pool or a newly created one.
- Note: This method uses the nib name as the reuse identifier.
*/
public func dequeueReusableCell<T: UICollectionViewCell>(
withNibName nibName: String,
bundle: Bundle?,
for sectionController: ListSectionController,
at index: Int
) -> T {
guard let cell = self.dequeueReusableCell(
withNibName: nibName,
bundle: bundle,
for: sectionController,
at: index
) as? T else {
fatalError("A nib named \"\(nibName)\" was not found in \(bundle)")
}
return cell
}
}