From 6224a6536c7b97fea1d4bafddb9fb5659a7678ac 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(fromStoryboardOfKind: Summary: add typesafe method for dequeueReusableSupplementaryView(fromStoryboardOfKind: Reviewed By: natestedman Differential Revision: D26238613 fbshipit-source-id: 15d18628fd54e2d7d0ff3cb0b1f88bb473bfbfed --- .../IGListCollectionContext+Refinements.swift | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/Source/IGListSwiftKit/IGListCollectionContext+Refinements.swift b/Source/IGListSwiftKit/IGListCollectionContext+Refinements.swift index 54ed020a..60716e08 100644 --- a/Source/IGListSwiftKit/IGListCollectionContext+Refinements.swift +++ b/Source/IGListSwiftKit/IGListCollectionContext+Refinements.swift @@ -147,4 +147,33 @@ extension ListCollectionContext { return supplementaryView } + + /** + Dequeues a supplementary view from the collection view reuse pool. + + - Parameters: + - elementKind: The kind of supplementary view. + - identifier: The identifier of the supplementary view in storyboard. + - 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. + */ + public func dequeueReusableSupplementaryViewFromStoryboard( + ofKind elementKind: String, + withIdentifier identifier: String, + forSectionController sectionController: ListSectionController, + atIndex index: Int + ) -> T { + guard let supplementaryView = self.dequeueReusableSupplementaryView( + fromStoryboardOfKind: elementKind, + withIdentifier: identifier, + for: sectionController, + at: index + ) as? T else { + fatalError() + } + + return supplementaryView + } }