From a7d720d0071b6f473f2f9ada56fbf6bef5111251 Mon Sep 17 00:00:00 2001 From: Jeff Bailey Date: Wed, 25 Jul 2018 14:31:05 -0700 Subject: [PATCH] IGListBindingSectionController no longer asserts when reloading the entire section. (#1213) Summary: Issue fixed: #1174 - [X] All tests pass. Demo project builds and runs. - [x] I added tests, an experiment, or detailed why my change isn't tested. - [X] I added an entry to the `CHANGELOG.md` for any breaking changes, enhancements, or bug fixes. - [X] I have reviewed the [contributing guide](https://github.com/Instagram/IGListKit/blob/master/.github/CONTRIBUTING.md) Pull Request resolved: https://github.com/Instagram/IGListKit/pull/1213 Differential Revision: D9003398 Pulled By: rnystrom fbshipit-source-id: 2c68f42e21abaea9191f26309668d866544f80b4 --- CHANGELOG.md | 2 ++ Source/IGListBindingSectionController.m | 9 ++++++--- Tests/Objects/IGTestDiffingObject.m | 14 ++++++++++++-- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c82063b4..15d954b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,8 @@ The changelog for `IGListKit`. Also see the [releases](https://github.com/instag - Added `IGListCollectionScrollingTraits` for exposing `UICollectionView` scrolling traits to section controllers via `IGListCollectionContext`. [Adam Stern](https://github.com/adamastern) (tbd) +- `IGListBindingSectionController` no longer asserts when reloading the entire section. A warning message is now logged if the entire section is going to be reloaded. [Jeff Bailey](https://github.com/jeffbailey) (#1213) + ### Fixes - Experimental fix to get the `UICollectionView` for batch updating immediately before applying the update. [Ryan Nystrom](https://github.com/rnystrom) (tbd) diff --git a/Source/IGListBindingSectionController.m b/Source/IGListBindingSectionController.m index 073ac314..0882ddd7 100644 --- a/Source/IGListBindingSectionController.m +++ b/Source/IGListBindingSectionController.m @@ -115,9 +115,12 @@ typedef NS_ENUM(NSInteger, IGListDiffingSectionState) { NSArray *viewModels = [self.dataSource sectionController:self viewModelsForObject:object]; self.viewModels = objectsWithDuplicateIdentifiersRemoved(viewModels); } else { - IGAssert([oldObject isEqualToDiffableObject:object], - @"Unequal objects %@ and %@ will cause IGListBindingSectionController to reload the entire section", - oldObject, object); +#if IGLK_LOGGING_ENABLED + if (![oldObject isEqualToDiffableObject:object]) { + IGLKLog(@"Warning: Unequal objects %@ and %@ will cause IGListBindingSectionController to reload the entire section", + oldObject, object); + } +#endif [self updateAnimated:YES completion:nil]; } } diff --git a/Tests/Objects/IGTestDiffingObject.m b/Tests/Objects/IGTestDiffingObject.m index ff14fb5a..e8a662f8 100644 --- a/Tests/Objects/IGTestDiffingObject.m +++ b/Tests/Objects/IGTestDiffingObject.m @@ -28,8 +28,18 @@ return self.key; } -- (BOOL)isEqualToDiffableObject:(id)object { - return YES; +- (BOOL)isEqualToDiffableObject:(id)object { + if (object == self) { + return YES; + } + if ([object isKindOfClass:[IGTestDiffingObject class]]) { + /* A simple equality test that only looks at the number of objects for the key. + It does not currently test the equality of each of the objects. */ + IGTestDiffingObject *testDiffingObject = (IGTestDiffingObject *)object; + return self.objects.count == testDiffingObject.objects.count; + } + + return NO; } @end