Skip reloading objects that are not found

Summary:
Even with the assert, we will add `NSNotFound` to the set which will crash. Instead, skip adding the value in case a consumer is using a reference to an object that doesn't exist anymore.

Also, should be using `continue` if a section controller isn't returned by the data source.

Reviewed By: jessesquires

Differential Revision: D4226771

fbshipit-source-id: ed6df0992fdef611dd8fae64f4716e296df11f9a
This commit is contained in:
Ryan Nystrom 2016-11-23 16:26:26 -08:00 committed by Facebook Github Bot
parent 8a6fde9e45
commit ca15e29cf1
3 changed files with 15 additions and 3 deletions

View file

@ -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)

View file

@ -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:

View file

@ -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