diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a3adc55..d4efe97f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -82,6 +82,8 @@ This release closes the [2.0.0 milestone](https://github.com/Instagram/IGListKit - Prevent `UICollectionView` bug when accessing a cell during working range updates. [Ryan Nystrom](https://github.com/rnystrom) [(#216)](https://github.com/Instagram/IGListKit/pull/216) +- Skip reloading for objects that are not found when calling `-[IGListAdapter reloadObjects:]`. [Ryan Nystrom](https://github.com/rnystrom) (tbd) + ### Documentation - We now have 100% documentation coverage. Docs been refined and clarified. [Jesse Squires](https://github.com/jessesquires) [(#207)](https://github.com/Instagram/IGListKit/pull/207) diff --git a/Source/IGListAdapter.m b/Source/IGListAdapter.m index 0cdf3c56..21f0087c 100644 --- a/Source/IGListAdapter.m +++ b/Source/IGListAdapter.m @@ -311,8 +311,11 @@ for (id object in objects) { // look up the item using the map's lookup function. might not be the same item - NSUInteger section = [map sectionForObject:object]; - IGAssert(section != NSNotFound, @"Did not find a section for item %@", object); + const NSInteger section = [map sectionForObject:object]; + const BOOL notFound = section == NSNotFound; + if (notFound) { + continue; + } [sections addIndex:section]; // reverse lookup the item using the section. if the pointer has changed the trigger update events and swap items @@ -465,7 +468,7 @@ IGAssert(sectionController != nil, @"Data source <%@> cannot return a nil section controller.", self.dataSource); if (sectionController == nil) { - break; + continue; } // in case the section controller was created outside of -listAdapter:sectionControllerForObject: diff --git a/Tests/IGListAdapterTests.m b/Tests/IGListAdapterTests.m index 6ad1c7cc..5cd4ae56 100644 --- a/Tests/IGListAdapterTests.m +++ b/Tests/IGListAdapterTests.m @@ -843,4 +843,11 @@ XCTAssertEqual(CGPointEqualToPoint(point, p), YES); \ [mockScrollDelegate verify]; } +- (void)test_whenReloadingObjectsThatDontExist_thatAdapterContinues { + self.dataSource.objects = @[@0, @1, @2]; + [self.adapter reloadDataWithCompletion:nil]; + [self.adapter reloadObjects:@[@1, @3]]; + XCTAssertEqual(self.collectionView.numberOfSections, 3); +} + @end