diff --git a/AsyncDisplayKit/Details/ASCollectionDataController.mm b/AsyncDisplayKit/Details/ASCollectionDataController.mm index ca5a48a84c..45f1d3af37 100644 --- a/AsyncDisplayKit/Details/ASCollectionDataController.mm +++ b/AsyncDisplayKit/Details/ASCollectionDataController.mm @@ -33,8 +33,7 @@ _pendingNodes = [NSMutableDictionary dictionary]; _pendingIndexPaths = [NSMutableDictionary dictionary]; - NSArray *elementKinds = [self.collectionDataSource supplementaryNodeKindsInDataController:self]; - [elementKinds enumerateObjectsUsingBlock:^(NSString *kind, NSUInteger idx, BOOL *stop) { + [[self supplementaryKinds] enumerateObjectsUsingBlock:^(NSString *kind, NSUInteger idx, BOOL *stop) { LOG(@"Populating elements of kind: %@", kind); NSMutableArray *indexPaths = [NSMutableArray array]; NSMutableArray *nodes = [NSMutableArray array]; @@ -76,8 +75,7 @@ - (void)prepareForInsertSections:(NSIndexSet *)sections { - NSArray *elementKinds = [self.collectionDataSource supplementaryNodeKindsInDataController:self]; - [elementKinds enumerateObjectsUsingBlock:^(NSString *kind, NSUInteger idx, BOOL *stop) { + [[self supplementaryKinds] enumerateObjectsUsingBlock:^(NSString *kind, NSUInteger idx, BOOL *stop) { LOG(@"Populating elements of kind: %@, for sections: %@", kind, sections); NSMutableArray *nodes = [NSMutableArray array]; NSMutableArray *indexPaths = [NSMutableArray array]; @@ -107,8 +105,7 @@ - (void)willDeleteSections:(NSIndexSet *)sections { - NSArray *elementKinds = [self.collectionDataSource supplementaryNodeKindsInDataController:self]; - [elementKinds enumerateObjectsUsingBlock:^(NSString *kind, NSUInteger idx, BOOL *stop) { + [[self supplementaryKinds] enumerateObjectsUsingBlock:^(NSString *kind, NSUInteger idx, BOOL *stop) { NSArray *indexPaths = ASIndexPathsForMultidimensionalArrayAtIndexSet([self editingNodesOfKind:kind], sections); [self deleteNodesOfKind:kind atIndexPaths:indexPaths completion:nil]; @@ -118,8 +115,7 @@ - (void)prepareForReloadSections:(NSIndexSet *)sections { - NSArray *elementKinds = [self.collectionDataSource supplementaryNodeKindsInDataController:self]; - [elementKinds enumerateObjectsUsingBlock:^(NSString *kind, NSUInteger idx, BOOL *stop) { + [[self supplementaryKinds] enumerateObjectsUsingBlock:^(NSString *kind, NSUInteger idx, BOOL *stop) { NSMutableArray *nodes = [NSMutableArray array]; NSMutableArray *indexPaths = [NSMutableArray array]; [self _populateSupplementaryNodesOfKind:kind withSections:sections mutableNodes:nodes mutableIndexPaths:indexPaths]; @@ -145,8 +141,7 @@ - (void)willMoveSection:(NSInteger)section toSection:(NSInteger)newSection { - NSArray *elementKinds = [self.collectionDataSource supplementaryNodeKindsInDataController:self]; - [elementKinds enumerateObjectsUsingBlock:^(NSString *kind, NSUInteger idx, BOOL *stop) { + [[self supplementaryKinds] enumerateObjectsUsingBlock:^(NSString *kind, NSUInteger idx, BOOL *stop) { NSArray *indexPaths = ASIndexPathsForMultidimensionalArrayAtIndexSet([self editingNodesOfKind:kind], [NSIndexSet indexSetWithIndex:section]); NSArray *nodes = ASFindElementsInMultidimensionalArrayAtIndexPaths([self editingNodesOfKind:kind], indexPaths); [self deleteNodesOfKind:kind atIndexPaths:indexPaths completion:nil]; @@ -209,6 +204,11 @@ #pragma mark - Private Helpers +- (NSArray *)supplementaryKinds +{ + return [self.collectionDataSource supplementaryNodeKindsInDataController:self]; +} + - (id)collectionDataSource { return (id)self.dataSource; diff --git a/AsyncDisplayKitTests/ASCollectionViewTests.m b/AsyncDisplayKitTests/ASCollectionViewTests.m index 1993d0734b..db993713b5 100644 --- a/AsyncDisplayKitTests/ASCollectionViewTests.m +++ b/AsyncDisplayKitTests/ASCollectionViewTests.m @@ -7,6 +7,7 @@ #import #import "ASCollectionView.h" +#import "ASCollectionDataController.h" #import "ASCollectionViewFlowLayoutInspector.h" @interface ASCollectionViewTestDelegate : NSObject @@ -74,6 +75,12 @@ @end +@interface ASCollectionView (InternalTesting) + +- (NSArray *)supplementaryNodeKindsInDataController:(ASCollectionDataController *)dataController; + +@end + @interface ASCollectionViewTests : XCTestCase @end @@ -95,6 +102,14 @@ XCTAssert(collectionView.layoutDelegate == nil, @"should not set a layout delegate for custom layouts"); } +- (void)testThatRegisteringASupplementaryNodeStoresItForIntrospection +{ + UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init]; + ASCollectionView *collectionView = [[ASCollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout]; + [collectionView registerSupplementaryNodeOfKind:UICollectionElementKindSectionHeader]; + XCTAssertEqualObjects([collectionView supplementaryNodeKindsInDataController:nil], @[UICollectionElementKindSectionHeader]); +} + - (void)DISABLED_testCollectionViewController { ASCollectionViewTestController *testController = [[ASCollectionViewTestController alloc] initWithNibName:nil bundle:nil];