diff --git a/CHANGELOG.md b/CHANGELOG.md index d11cecf8..83d9390d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,8 +17,6 @@ The changelog for `IGListKit`. Also see the [releases](https://github.com/instag ### Fixes -- Duplicate objects for initial data source setup filtered out. [Mikhail Vashlyaev](https://github.com/yemodin) [(#993](https://github.com/Instagram/IGListKit/pull/993) - - Weakly reference the `UICollectionView` in coalescence so that it can be released if the rest of system is destroyed. [Ryan Nystrom](https://github.com/rnystrom) [(#tbd)](https://github.com/Instagram/IGListKit/pull/tbd) - Fix bug with `-[IGListAdapter scrollToObject:supplementaryKinds:scrollDirection:scrollPosition:animated:]` where the content inset of the collection view was incorrectly being applied to the final offset. [Ryan Nystrom](https://github.com/rnystrom) [(#tbd)](https://github.com/Instagram/IGListKit/pull/tbd) diff --git a/Source/Common/Internal/IGListArrayUtilsInternal.h b/Source/Common/Internal/IGListArrayUtilsInternal.h index e32b7c30..e3aed12a 100644 --- a/Source/Common/Internal/IGListArrayUtilsInternal.h +++ b/Source/Common/Internal/IGListArrayUtilsInternal.h @@ -24,7 +24,7 @@ static NSArray *objectsWithDuplicateIdentifiersRemoved(NSArray *_viewSectionControllerMap; @@ -144,8 +143,7 @@ - (void)updateAfterPublicSettingsChange { id dataSource = _dataSource; if (_collectionView != nil && dataSource != nil) { - NSArray *uniqueObjects = objectsWithDuplicateIdentifiersRemoved([dataSource objectsForListAdapter:self]); - [self updateObjects:uniqueObjects dataSource:dataSource]; + [self updateObjects:[[dataSource objectsForListAdapter:self] copy] dataSource:dataSource]; } } @@ -361,13 +359,13 @@ return; } - NSArray *uniqueObjects = objectsWithDuplicateIdentifiersRemoved([dataSource objectsForListAdapter:self]); + NSArray *newItems = [[dataSource objectsForListAdapter:self] copy]; __weak __typeof__(self) weakSelf = self; [self.updater reloadDataWithCollectionView:collectionView reloadUpdateBlock:^{ // purge all section controllers from the item map so that they are regenerated [weakSelf.sectionMap reset]; - [weakSelf updateObjects:uniqueObjects dataSource:dataSource]; + [weakSelf updateObjects:newItems dataSource:dataSource]; } completion:^(BOOL finished) { [weakSelf notifyDidUpdate:IGListAdapterUpdateTypeReloadData animated:NO]; if (completion) { @@ -577,8 +575,11 @@ IGParameterAssert(dataSource != nil); #if DEBUG + NSCountedSet *identifiersSet = [NSCountedSet new]; for (id object in objects) { + [identifiersSet addObject:[object diffIdentifier]]; IGAssert([object isEqualToDiffableObject:object], @"Object instance %@ not equal to itself. This will break infra map tables.", object); + IGAssert([identifiersSet countForObject:[object diffIdentifier]] <= 1, @"Diff identifier %@ for object %@ occurs more than once. Identifiers must be unique!", [object diffIdentifier], object); } #endif diff --git a/Tests/IGListAdapterTests.m b/Tests/IGListAdapterTests.m index 101d45b5..59608907 100644 --- a/Tests/IGListAdapterTests.m +++ b/Tests/IGListAdapterTests.m @@ -1527,11 +1527,9 @@ XCTAssertEqual(collectionView1.dataSource, adapter2); } -- (void)test_whenPassingNonUniqueIdentifiers_adapterReloadShouldSkipDuplicates { +- (void)test_whenPassingNonUniqueIdentifiers_adapterShouldAssert { self.dataSource.objects = @[@0, @1, @2, @0]; - [self.adapter reloadDataWithCompletion:nil]; - - XCTAssertEqual(self.adapter.objects.count, 3); + XCTAssertThrows([self.adapter reloadDataWithCompletion:nil]); } - (void)test_whenPrefetchingEnabled_thatSetterDisables { diff --git a/Tests/IGListDebuggerTests.m b/Tests/IGListDebuggerTests.m index a687a89d..ad3f0e38 100644 --- a/Tests/IGListDebuggerTests.m +++ b/Tests/IGListDebuggerTests.m @@ -45,7 +45,7 @@ adapter3.collectionView = collectionView; NSArray *descriptions = [IGListDebugger adapterDescriptions]; - XCTAssertEqual(descriptions.count, 3); + XCTAssertEqual(descriptions.count, 4); } @end