From 6d6cbe1a2fe732a04b50efb1bcc4bc1809681ef2 Mon Sep 17 00:00:00 2001 From: Vivian Phung Date: Fri, 5 Feb 2021 09:34:26 -0800 Subject: [PATCH] IGListCollectionContext typesafe method for dequeueReusableSupplementaryView(ofKind: ... nibName: Summary: add typesafe method for dequeueReusableSupplementaryView(ofKind: ... nibName: Reviewed By: natestedman Differential Revision: D26238618 fbshipit-source-id: 50b99311594fa0987752980025a927da1513b55d --- Source/IGListKit/IGListCollectionContext.h | 2 +- .../IGListCollectionContext+Refinements.swift | 38 ++++++++++++++++++- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/Source/IGListKit/IGListCollectionContext.h b/Source/IGListKit/IGListCollectionContext.h index 9c64e78d..745434be 100644 --- a/Source/IGListKit/IGListCollectionContext.h +++ b/Source/IGListKit/IGListCollectionContext.h @@ -240,7 +240,7 @@ NS_SWIFT_NAME(ListCollectionContext) @return A supplementary view dequeued from the reuse pool or a newly created one. - @note This method uses a string representation of the view class as the identifier. + @note This method uses the nib name as the reuse identifier. */ - (__kindof UICollectionReusableView *)dequeueReusableSupplementaryViewOfKind:(NSString *)elementKind forSectionController:(IGListSectionController *)sectionController diff --git a/Source/IGListSwiftKit/IGListCollectionContext+Refinements.swift b/Source/IGListSwiftKit/IGListCollectionContext+Refinements.swift index 60716e08..1567c3d8 100644 --- a/Source/IGListSwiftKit/IGListCollectionContext+Refinements.swift +++ b/Source/IGListSwiftKit/IGListCollectionContext+Refinements.swift @@ -147,7 +147,7 @@ extension ListCollectionContext { return supplementaryView } - + /** Dequeues a supplementary view from the collection view reuse pool. @@ -173,7 +173,41 @@ extension ListCollectionContext { ) as? T else { fatalError() } - + + return supplementaryView + } + + /** + Dequeues a supplementary view from the collection view reuse pool. + + - Parameters: + - elementKind: The kind of supplementary view. + - sectionController: The section controller requesting this information. + - 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. + - index: The index of the supplementary view. + + - Returns: A supplementary view dequeued from the reuse pool or a newly created one. + + - Note: This method uses the nib name as the reuse identifier. + */ + public func dequeueReusableSupplementaryView( + ofKind elementKind: String, + forSectionController sectionController: ListSectionController, + nibName: String, + bundle: Bundle?, + atIndex index: Int + ) -> T { + guard let supplementaryView = self.dequeueReusableSupplementaryView( + ofKind: elementKind, + for: sectionController, + nibName: nibName, + bundle: bundle, + at: index + ) as? T else { + fatalError() + } + return supplementaryView } }