diff --git a/Source/IGListDiffKit/IGListExperiments.h b/Source/IGListDiffKit/IGListExperiments.h index 826c29419..1c660a88c 100644 --- a/Source/IGListDiffKit/IGListExperiments.h +++ b/Source/IGListDiffKit/IGListExperiments.h @@ -19,7 +19,9 @@ typedef NS_OPTIONS (NSInteger, IGListExperiment) { /// Test invalidating layout when cell reloads/updates in IGListBindingSectionController. IGListExperimentInvalidateLayoutForUpdates = 1 << 2, /// Throw NSInternalInconsistencyException during an update - IGListExperimentThrowOnInconsistencyException = 1 << 3 + IGListExperimentThrowOnInconsistencyException = 1 << 3, + /// Test keeping a strong pointer to the collectionView.dataSource during a batch update to avoid a crash + IGListExperimentKeepPointerToCollectionViewDataSource = 1 << 4 }; /** diff --git a/Source/IGListKit/Internal/IGListBatchUpdateTransaction.m b/Source/IGListKit/Internal/IGListBatchUpdateTransaction.m index d497998d6..14fd9da0d 100644 --- a/Source/IGListKit/Internal/IGListBatchUpdateTransaction.m +++ b/Source/IGListKit/Internal/IGListBatchUpdateTransaction.m @@ -136,7 +136,11 @@ - (void)_didDiff:(IGListIndexSetResult *)diffResult onBackground:(BOOL)onBackgro [self.delegate listAdapterUpdater:self.updater didDiffWithResults:diffResult onBackgroundThread:onBackground]; @try { - if (self.collectionView.dataSource == nil) { + // Experiment with keeping a pointer to the self.collectionView.dataSource, because we're seeing a crash where it could be missing. + const BOOL keepDataSource = IGListExperimentEnabled(self.config.experiments, IGListExperimentKeepPointerToCollectionViewDataSource); + id const collectionViewDataSource = keepDataSource ? self.collectionView.dataSource : nil; + + if (self.collectionView.dataSource == nil || (keepDataSource && collectionViewDataSource == nil)) { // If the data source is nil, we should not call any collection view update. [self _bail]; } else if (diffResult.changeCount > 100 && self.config.allowsReloadingOnTooManyUpdates) {