diff --git a/Source/Internal/IGListSectionMap.m b/Source/Internal/IGListSectionMap.m index 323cde0c..bce0927a 100644 --- a/Source/Internal/IGListSectionMap.m +++ b/Source/Internal/IGListSectionMap.m @@ -75,7 +75,12 @@ } - (id)objectForSection:(NSUInteger)section { - return self.objects[section]; + NSArray *objects = self.objects; + if (section < objects.count) { + return objects[section]; + } else { + return nil; + } } - (NSUInteger)sectionForObject:(id)object { diff --git a/Tests/IGListObjectMapTests.m b/Tests/IGListSectionMapTests.m similarity index 90% rename from Tests/IGListObjectMapTests.m rename to Tests/IGListSectionMapTests.m index c19200bf..9d210614 100644 --- a/Tests/IGListObjectMapTests.m +++ b/Tests/IGListSectionMapTests.m @@ -82,4 +82,12 @@ XCTAssertEqual(counter, 2); } +- (void)test_whenAccessingOOBSection_thatNilIsReturned { + NSArray *objects = @[@0, @1, @2]; + NSArray *sectionControllers = @[@"a", @"b", @"c"]; + IGListSectionMap *map = [[IGListSectionMap alloc] initWithMapTable:[NSMapTable strongToStrongObjectsMapTable]]; + [map updateWithObjects:objects sectionControllers:sectionControllers]; + XCTAssertNil([map objectForSection:4]); +} + @end