From 44c009b6fcafef5bc100eafa48ea3ea541b61b7f Mon Sep 17 00:00:00 2001 From: Brandon Kieft Date: Wed, 13 Oct 2021 19:04:03 -0700 Subject: [PATCH] Add TEMP code to print the delegate class in the assert message Summary: Trying to track down the causes of this assert. Unfortunately the assert does not tell us which class is returning the bad info. Add some HACKY TEMP code to print out the class name in some cases. Hopefully this will catch all the issues. I put the code in a static function called within the assert, so it should be compiled out of prod builds. Differential Revision: D31482081 fbshipit-source-id: bef0274c0e35b90d5f77b0cfd337e3f9a772e8b8 --- .../IGListKit/IGListCollectionViewLayout.mm | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/Source/IGListKit/IGListCollectionViewLayout.mm b/Source/IGListKit/IGListCollectionViewLayout.mm index 28597a47..e69ef50f 100644 --- a/Source/IGListKit/IGListCollectionViewLayout.mm +++ b/Source/IGListKit/IGListCollectionViewLayout.mm @@ -18,6 +18,7 @@ #import "IGListCollectionViewDelegateLayout.h" #import "UIScrollView+IGListKit.h" +#import "IGListAdapter.h" static CGFloat UIEdgeInsetsLeadingInsetInDirection(UIEdgeInsets insets, UICollectionViewScrollDirection direction) { switch (direction) { @@ -459,6 +460,21 @@ static void adjustZIndexForAttributes(UICollectionViewLayoutAttributes *attribut #pragma mark - Private API +- (NSString *)_classNameForDelegate:(id)delegate sectionIndex:(NSInteger)section { + NSString *const delegateClassString = NSStringFromClass(delegate.class); + if ([delegateClassString isEqualToString:@"IGListAdapterProxy"] == NO) { + return delegateClassString; + } + + id forwardingObject = [(id)delegate forwardingTargetForSelector:@selector(collectionView:layout:insetForSectionAtIndex:)]; + if ([forwardingObject isKindOfClass:IGListAdapter.class] == NO) { + return NSStringFromClass([forwardingObject class]); + } + + id sectionController = [forwardingObject sectionControllerForSection:section]; + return NSStringFromClass([sectionController class]); +} + - (void)_calculateLayoutIfNeeded { if (_minimumInvalidatedSection == NSNotFound) { return; @@ -532,13 +548,14 @@ static void adjustZIndexForAttributes(UICollectionViewLayoutAttributes *attribut IGAssert(CGSizeGetLengthInDirection(size, fixedDirection) <= paddedLengthInFixedDirection || fabs(CGSizeGetLengthInDirection(size, fixedDirection) - paddedLengthInFixedDirection) < FLT_EPSILON, - @"%@ of item %li in section %li (%.0f pt) must be less than or equal to container (%.0f pt) accounting for section insets %@", + @"%@ of item %li in section %li (%.0f pt) must be less than or equal to container (%.0f pt) accounting for section insets %@. Delegate class: %@", self.scrollDirection == UICollectionViewScrollDirectionVertical ? @"Width" : @"Height", (long)item, (long)section, CGSizeGetLengthInDirection(size, fixedDirection), CGRectGetLengthInDirection(contentInsetAdjustedCollectionViewBounds, fixedDirection), - NSStringFromUIEdgeInsets(insets)); + NSStringFromUIEdgeInsets(insets), + [self _classNameForDelegate:delegate sectionIndex:section]); CGFloat itemLengthInFixedDirection = MIN(CGSizeGetLengthInDirection(size, fixedDirection), paddedLengthInFixedDirection);