diff --git a/Source/IGListAdapter.m b/Source/IGListAdapter.m index 36b21956..cb9524b2 100644 --- a/Source/IGListAdapter.m +++ b/Source/IGListAdapter.m @@ -443,15 +443,6 @@ _collectionView.backgroundView.hidden = itemCount > 0; } -// use the string representation of a reusable view class when registering with a UICollectionView -- (NSString *)reusableViewIdentifierForClass:(Class)viewClass { - return NSStringFromClass(viewClass); -} - -- (NSString *)reusableViewIdentifierForClass:(Class)viewClass elementKind:(NSString *)elementKind { - return [elementKind stringByAppendingString:NSStringFromClass(viewClass)]; -} - - (IGListSectionMap *)sectionMapAdjustForUpdateBlock:(BOOL)adjustForUpdateBlock { // if we are inside an update block, we may have to use the /previous/ item map for some operations if (adjustForUpdateBlock && self.isInUpdateBlock && self.previoussectionMap != nil) { @@ -720,7 +711,7 @@ IGParameterAssert(cellClass != nil); UICollectionView *collectionView = self.collectionView; IGAssert(collectionView != nil, @"Reloading adapter without a collection view."); - NSString *identifier = [self reusableViewIdentifierForClass:cellClass]; + NSString *identifier = IGListReusableViewIdentifier(cellClass, nil); NSIndexPath *indexPath = [self indexPathForSectionController:sectionController index:index]; if (![self.registeredCellClasses containsObject:cellClass]) { [self.registeredCellClasses addObject:cellClass]; @@ -736,7 +727,7 @@ IGAssertMainThread(); UICollectionView *collectionView = self.collectionView; IGAssert(collectionView != nil, @"Reloading adapter without a collection view."); - NSString *identifier = [self reusableViewIdentifierForClass:viewClass elementKind:elementKind]; + NSString *identifier = IGListReusableViewIdentifier(viewClass, elementKind); NSIndexPath *indexPath = [self indexPathForSectionController:sectionController index:index]; if (![self.registeredSupplementaryViewIdentifiers containsObject:identifier]) { [self.registeredSupplementaryViewIdentifiers addObject:identifier]; diff --git a/Source/Internal/IGListAdapterInternal.h b/Source/Internal/IGListAdapterInternal.h index 3dd217ab..9f1e5701 100644 --- a/Source/Internal/IGListAdapterInternal.h +++ b/Source/Internal/IGListAdapterInternal.h @@ -17,6 +17,11 @@ NS_ASSUME_NONNULL_BEGIN +/// Generate a string representation of a reusable view class when registering with a UICollectionView. +NS_INLINE NSString *IGListReusableViewIdentifier(Class viewClass, NSString * _Nullable kind) { + return [NSString stringWithFormat:@"%@%@", kind ?: @"", NSStringFromClass(viewClass)]; +} + @interface IGListAdapter () < UICollectionViewDataSource, @@ -55,8 +60,6 @@ IGListCollectionContext indexes:(NSIndexSet *)indexes adjustForUpdateBlock:(BOOL)adjustForUpdateBlock; -- (NSString *)reusableViewIdentifierForClass:(Class)viewClass; - @end NS_ASSUME_NONNULL_END diff --git a/Tests/IGListAdapterTests.m b/Tests/IGListAdapterTests.m index 08d15e34..de7c307d 100644 --- a/Tests/IGListAdapterTests.m +++ b/Tests/IGListAdapterTests.m @@ -143,10 +143,15 @@ } - (void)test_whenQueryingReusableIdentifier_thatIdentifierEqualsClassName { - NSString *identifier = [self.adapter reusableViewIdentifierForClass:UICollectionViewCell.class]; + NSString *identifier = IGListReusableViewIdentifier(UICollectionViewCell.class, nil); XCTAssertEqualObjects(identifier, @"UICollectionViewCell"); } +- (void)test_whenQueryingReusableIdentifier_thatIdentifierEqualsClassNameAndSupplimentaryKind { + NSString *identifier = IGListReusableViewIdentifier(UICollectionViewCell.class, UICollectionElementKindSectionFooter); + XCTAssertEqualObjects(identifier, @"UICollectionElementKindSectionFooterUICollectionViewCell"); +} + - (void)test_whenDataSourceChanges_thatBackgroundViewVisibilityChanges { self.dataSource.objects = @[@1]; UIView *background = [[UIView alloc] init];