From bfe35fc0b10d41d53f8a64e250476f93b8bfe040 Mon Sep 17 00:00:00 2001 From: Adlai Holler Date: Fri, 10 Mar 2017 06:35:20 -0800 Subject: [PATCH] Add production workaround for missing elements (#3158) --- Source/ASCollectionView.mm | 12 ++++++++++-- Source/Private/ASElementMap.m | 18 +++++++++++++++++- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/Source/ASCollectionView.mm b/Source/ASCollectionView.mm index 25fc6f54d7..d1f626c021 100644 --- a/Source/ASCollectionView.mm +++ b/Source/ASCollectionView.mm @@ -1740,14 +1740,22 @@ static NSString * const kReuseIdentifier = @"_ASCollectionReuseIdentifier"; // Visible items for (NSIndexPath *indexPath in self.indexPathsForVisibleItems) { ASCollectionElement *element = [map elementForItemAtIndexPath:indexPath]; - [result addObject:element]; + if (element != nil) { + [result addObject:element]; + } else { + ASDisplayNodeFailAssert(@"Couldn't find 'visible' item at index path %@ in map %@", indexPath, map); + } } // Visible supplementary elements for (NSString *kind in map.supplementaryElementKinds) { for (NSIndexPath *indexPath in [self asdk_indexPathsForVisibleSupplementaryElementsOfKind:kind]) { ASCollectionElement *element = [map supplementaryElementOfKind:kind atIndexPath:indexPath]; - [result addObject:element]; + if (element != nil) { + [result addObject:element]; + } else { + ASDisplayNodeFailAssert(@"Couldn't find 'visible' supplementary element of kind %@ at index path %@ in map %@", kind, indexPath, map); + } } } return result; diff --git a/Source/Private/ASElementMap.m b/Source/Private/ASElementMap.m index e3ce884b20..94d9658ce5 100644 --- a/Source/Private/ASElementMap.m +++ b/Source/Private/ASElementMap.m @@ -13,8 +13,9 @@ #import #import #import +#import -@interface ASElementMap () +@interface ASElementMap () @property (nonatomic, strong, readonly) NSArray *sections; @@ -168,6 +169,21 @@ return [_elementToIndexPathMap countByEnumeratingWithState:state objects:buffer count:len]; } +#pragma mark - ASDescriptionProvider + +- (NSString *)description +{ + return ASObjectDescriptionMake(self, [self propertiesForDescription]); +} + +- (NSMutableArray *)propertiesForDescription +{ + NSMutableArray *result = [NSMutableArray array]; + [result addObject:@{ @"items" : _sectionsOfItems }]; + [result addObject:@{ @"supplementaryElements" : _supplementaryElements }]; + return result; +} + #pragma mark - Internal /**