From dd3726343d06b5672a4cf1d342ddb9e6789648a5 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 Summary: add typesafe method for dequeueReusableSupplementaryView(:ofKind Reviewed By: natestedman Differential Revision: D26238603 fbshipit-source-id: 178bee6da1957a132c73610b9db0796323cbff26 --- Source/IGListKit/IGListCollectionContext.h | 2 +- .../IGListCollectionContext+Refinements.swift | 29 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/Source/IGListKit/IGListCollectionContext.h b/Source/IGListKit/IGListCollectionContext.h index dcbc2663..9c64e78d 100644 --- a/Source/IGListKit/IGListCollectionContext.h +++ b/Source/IGListKit/IGListCollectionContext.h @@ -208,7 +208,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 a string representation of the view class and the kind as the identifier. */ - (__kindof UICollectionReusableView *)dequeueReusableSupplementaryViewOfKind:(NSString *)elementKind forSectionController:(IGListSectionController *)sectionController diff --git a/Source/IGListSwiftKit/IGListCollectionContext+Refinements.swift b/Source/IGListSwiftKit/IGListCollectionContext+Refinements.swift index 3da2a52d..54ed020a 100644 --- a/Source/IGListSwiftKit/IGListCollectionContext+Refinements.swift +++ b/Source/IGListSwiftKit/IGListCollectionContext+Refinements.swift @@ -118,4 +118,33 @@ extension ListCollectionContext { return cell } + + /** + Dequeues a supplementary view from the collection view reuse pool. + + - Parameters: + - elementKind: The kind of supplementary view. + - sectionController: The section controller requesting this information. + - 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 a string representation of the view class and the kind as the identifier. + */ + public func dequeueReusableSupplementaryView( + ofKind elementKind: String, + forSectionController sectionController: ListSectionController, + atIndex index: NSInteger + ) -> T { + guard let supplementaryView = self.dequeueReusableSupplementaryView( + ofKind: elementKind, + for: sectionController, + class: T.self, + at: index + ) as? T else { + fatalError() + } + + return supplementaryView + } }