diff --git a/AsyncDisplayKit/Details/ASCollectionDataController.mm b/AsyncDisplayKit/Details/ASCollectionDataController.mm index b0f033d017..f3bcede28c 100644 --- a/AsyncDisplayKit/Details/ASCollectionDataController.mm +++ b/AsyncDisplayKit/Details/ASCollectionDataController.mm @@ -88,8 +88,7 @@ - (void)willInsertSections:(NSIndexSet *)sections { - for (NSString *kind in _pendingContexts) { - NSMutableArray *contexts = _pendingContexts[kind]; + [_pendingContexts enumerateKeysAndObjectsUsingBlock:^(NSString * _Nonnull kind, NSMutableArray * _Nonnull contexts, BOOL * _Nonnull stop) { NSMutableArray *sectionArray = [NSMutableArray arrayWithCapacity:sections.count]; for (NSUInteger i = 0; i < sections.count; i++) { [sectionArray addObject:[NSMutableArray array]]; @@ -99,7 +98,7 @@ [self batchLayoutNodesFromContexts:contexts ofKind:kind completion:^(NSArray *nodes, NSArray *indexPaths) { [self insertNodes:nodes ofKind:kind atIndexPaths:indexPaths completion:nil]; }]; - } + }]; [_pendingContexts removeAllObjects]; } @@ -145,13 +144,12 @@ - (void)willInsertRowsAtIndexPaths:(NSArray *)indexPaths { - for (NSString *kind in _pendingContexts) { - NSMutableArray *contexts = _pendingContexts[kind]; - + [_pendingContexts enumerateKeysAndObjectsUsingBlock:^(NSString * _Nonnull kind, NSMutableArray * _Nonnull contexts, BOOL * _Nonnull stop) { [self batchLayoutNodesFromContexts:contexts ofKind:kind completion:^(NSArray *nodes, NSArray *indexPaths) { [self insertNodes:nodes ofKind:kind atIndexPaths:indexPaths completion:nil]; }]; - } + }]; + [_pendingContexts removeAllObjects]; }