From 0a416914d57739604823b2e6cb9a55a28318acea Mon Sep 17 00:00:00 2001 From: Ryan Nystrom Date: Thu, 11 May 2017 14:46:22 -0700 Subject: [PATCH] Rename sectionIndex API to just section Summary: Quick rename before releasing 3.0 to get this API in parity w/ `isFirstSection` and `isLastSection`. My b I should have caught this in review. Closes #720 Reviewed By: jessesquires, amonshiz Differential Revision: D5031184 fbshipit-source-id: 1cd7b00c8b32084fecd861e78808eea0d0056337 --- .../DisplaySectionController.swift | 10 ++--- .../ListeningSectionController.swift | 2 +- .../WorkingRangeSectionController.swift | 2 +- Source/IGListSectionController.h | 7 ++- Source/IGListSectionController.m | 2 +- Source/IGListStackedSectionController.m | 2 +- .../IGListSectionControllerInternal.h | 2 +- Source/Internal/IGListSectionMap.m | 4 +- Tests/IGListAdapterE2ETests.m | 2 +- Tests/IGListAdapterTests.m | 45 +++++++++---------- Tests/IGListSectionMapTests.m | 4 +- Tests/IGListStackSectionControllerTests.m | 12 ++--- 12 files changed, 48 insertions(+), 46 deletions(-) diff --git a/Examples/Examples-iOS/IGListKitExamples/SectionControllers/DisplaySectionController.swift b/Examples/Examples-iOS/IGListKitExamples/SectionControllers/DisplaySectionController.swift index a3537d51e..c495ba804 100644 --- a/Examples/Examples-iOS/IGListKitExamples/SectionControllers/DisplaySectionController.swift +++ b/Examples/Examples-iOS/IGListKitExamples/SectionControllers/DisplaySectionController.swift @@ -33,26 +33,26 @@ final class DisplaySectionController: ListSectionController, ListDisplayDelegate override func cellForItem(at index: Int) -> UICollectionViewCell { let cell = collectionContext!.dequeueReusableCell(of: LabelCell.self, for: self, at: index) as! LabelCell - cell.text = "Section \(self.sectionIndex), cell \(index)" + cell.text = "Section \(self.section), cell \(index)" return cell } // MARK: ListDisplayDelegate func listAdapter(_ listAdapter: ListAdapter, willDisplay sectionController: ListSectionController) { - print("Will display section \(self.sectionIndex)") + print("Will display section \(self.section)") } func listAdapter(_ listAdapter: ListAdapter, willDisplay sectionController: ListSectionController, cell: UICollectionViewCell, at index: Int) { - print("Did will display cell \(index) in section \(self.sectionIndex)") + print("Did will display cell \(index) in section \(self.section)") } func listAdapter(_ listAdapter: ListAdapter, didEndDisplaying sectionController: ListSectionController) { - print("Did end displaying section \(self.sectionIndex)") + print("Did end displaying section \(self.section)") } func listAdapter(_ listAdapter: ListAdapter, didEndDisplaying sectionController: ListSectionController, cell: UICollectionViewCell, at index: Int) { - print("Did end displaying cell \(index) in section \(self.sectionIndex)") + print("Did end displaying cell \(index) in section \(self.section)") } } diff --git a/Examples/Examples-iOS/IGListKitExamples/SectionControllers/ListeningSectionController.swift b/Examples/Examples-iOS/IGListKitExamples/SectionControllers/ListeningSectionController.swift index 82e77b57f..6d0ebeb55 100644 --- a/Examples/Examples-iOS/IGListKitExamples/SectionControllers/ListeningSectionController.swift +++ b/Examples/Examples-iOS/IGListKitExamples/SectionControllers/ListeningSectionController.swift @@ -24,7 +24,7 @@ final class ListeningSectionController: ListSectionController, IncrementListener } func configureCell(cell: LabelCell) { - cell.text = "Section: \(self.sectionIndex), value: \(value)" + cell.text = "Section: \(self.section), value: \(value)" } // MARK: ListSectionController Overrides diff --git a/Examples/Examples-iOS/IGListKitExamples/SectionControllers/WorkingRangeSectionController.swift b/Examples/Examples-iOS/IGListKitExamples/SectionControllers/WorkingRangeSectionController.swift index 19a675df2..2fef7182e 100644 --- a/Examples/Examples-iOS/IGListKitExamples/SectionControllers/WorkingRangeSectionController.swift +++ b/Examples/Examples-iOS/IGListKitExamples/SectionControllers/WorkingRangeSectionController.swift @@ -71,7 +71,7 @@ final class WorkingRangeSectionController: ListSectionController, ListWorkingRan let url = URL(string: urlString) else { return } - print("Downloading image \(urlString) for section \(self.sectionIndex)") + print("Downloading image \(urlString) for section \(self.section)") task = URLSession.shared.dataTask(with: url) { data, response, err in guard let data = data, let image = UIImage(data: data) else { diff --git a/Source/IGListSectionController.h b/Source/IGListSectionController.h index 6755ced72..52d17f053 100644 --- a/Source/IGListSectionController.h +++ b/Source/IGListSectionController.h @@ -99,9 +99,12 @@ NS_SWIFT_NAME(ListSectionController) @property (nonatomic, weak, nullable, readonly) id collectionContext; /** - Returns the index within the list for this section controller. + Returns the section within the list for this section controller. + + @note This value also relates to the section within a `UICollectionView` that this section controller's cells belong. + It also relates to the `-[NSIndexPath section]` value for individual cells within the collection view. */ -@property (nonatomic, assign, readonly) NSInteger sectionIndex; +@property (nonatomic, assign, readonly) NSInteger section; /** Returns `YES` if the section controller is the first section in the list, `NO` otherwise. diff --git a/Source/IGListSectionController.m b/Source/IGListSectionController.m index 440a23fff..84accbc49 100644 --- a/Source/IGListSectionController.m +++ b/Source/IGListSectionController.m @@ -62,7 +62,7 @@ - (instancetype)init { _minimumInteritemSpacing = 0.0; _minimumLineSpacing = 0.0; _inset = UIEdgeInsetsZero; - _sectionIndex = NSNotFound; + _section = NSNotFound; } return self; } diff --git a/Source/IGListStackedSectionController.m b/Source/IGListStackedSectionController.m index 54307bbf0..bbe4a6df6 100644 --- a/Source/IGListStackedSectionController.m +++ b/Source/IGListStackedSectionController.m @@ -148,7 +148,7 @@ - (UICollectionViewCell *)cellForItemAtIndex:(NSInteger)index { - (void)didUpdateToObject:(id)object { for (IGListSectionController *sectionController in self.sectionControllers) { - sectionController.sectionIndex = self.sectionIndex; + sectionController.section = self.section; [sectionController didUpdateToObject:object]; } [self reloadData]; diff --git a/Source/Internal/IGListSectionControllerInternal.h b/Source/Internal/IGListSectionControllerInternal.h index 40758b564..e450039cd 100644 --- a/Source/Internal/IGListSectionControllerInternal.h +++ b/Source/Internal/IGListSectionControllerInternal.h @@ -19,7 +19,7 @@ FOUNDATION_EXTERN void IGListSectionControllerPopThread(void); @property (nonatomic, weak, readwrite) UIViewController *viewController; -@property (nonatomic, assign, readwrite) NSInteger sectionIndex; +@property (nonatomic, assign, readwrite) NSInteger section; @property (nonatomic, assign, readwrite) BOOL isFirstSection; diff --git a/Source/Internal/IGListSectionMap.m b/Source/Internal/IGListSectionMap.m index 59cfee1de..7f6f1aca8 100644 --- a/Source/Internal/IGListSectionMap.m +++ b/Source/Internal/IGListSectionMap.m @@ -77,7 +77,7 @@ - (void)updateWithObjects:(NSArray *)objects sectionControllers:(NSArray *)secti sectionController.isFirstSection = (object == firstObject); sectionController.isLastSection = (object == lastObject); - sectionController.sectionIndex = (NSInteger)idx; + sectionController.section = (NSInteger)idx; }]; } @@ -109,7 +109,7 @@ - (NSInteger)sectionForObject:(id)object { - (void)reset { [self enumerateUsingBlock:^(id _Nonnull object, IGListSectionController * _Nonnull sectionController, NSInteger section, BOOL * _Nonnull stop) { - sectionController.sectionIndex = NSNotFound; + sectionController.section = NSNotFound; sectionController.isFirstSection = NO; sectionController.isLastSection = NO; }]; diff --git a/Tests/IGListAdapterE2ETests.m b/Tests/IGListAdapterE2ETests.m index 24f3dec32..70a192b3c 100644 --- a/Tests/IGListAdapterE2ETests.m +++ b/Tests/IGListAdapterE2ETests.m @@ -521,7 +521,7 @@ - (void)test_whenQueryingCollectionContext_withNewItemInstances_thatSectionMatch __weak __typeof__(sectionController) weakSectionController = sectionController; sectionController.itemUpdateBlock = ^{ executedUpdateBlock = YES; - XCTAssertEqual(weakSectionController.sectionIndex, 1); + XCTAssertEqual(weakSectionController.section, 1); }; [self.adapter performUpdatesAnimated:YES completion:^(BOOL finished3) { diff --git a/Tests/IGListAdapterTests.m b/Tests/IGListAdapterTests.m index 54cf51eaa..a3881b104 100644 --- a/Tests/IGListAdapterTests.m +++ b/Tests/IGListAdapterTests.m @@ -1098,26 +1098,26 @@ - (void)test_whenInsertingAtBeginning_thatAllSectionControllerIndexesUpdateCorre [self.adapter performUpdatesAnimated:NO completion:nil]; IGListSectionController *controller1a = [self.adapter sectionControllerForObject:one]; - XCTAssertEqual(controller1a.sectionIndex, 0); + XCTAssertEqual(controller1a.section, 0); XCTAssertTrue(controller1a.isFirstSection); - XCTAssertEqual([self.adapter sectionControllerForObject:two].sectionIndex, 1); - XCTAssertEqual([self.adapter sectionControllerForObject:three].sectionIndex, 2); + XCTAssertEqual([self.adapter sectionControllerForObject:two].section, 1); + XCTAssertEqual([self.adapter sectionControllerForObject:three].section, 2); XCTAssertTrue([self.adapter sectionControllerForObject:three].isLastSection); self.dataSource.objects = @[zero, one, two, three]; [self.adapter performUpdatesAnimated:NO completion:nil]; IGListSectionController *controller0 = [self.adapter sectionControllerForObject:zero]; - XCTAssertEqual(controller0.sectionIndex, 0); + XCTAssertEqual(controller0.section, 0); XCTAssertTrue(controller0.isFirstSection); IGListSectionController *controller1b = [self.adapter sectionControllerForObject:one]; - XCTAssertEqual(controller1b.sectionIndex, 1); + XCTAssertEqual(controller1b.section, 1); XCTAssertFalse(controller1b.isFirstSection); - XCTAssertEqual([self.adapter sectionControllerForObject:two].sectionIndex, 2); - XCTAssertEqual([self.adapter sectionControllerForObject:three].sectionIndex, 3); + XCTAssertEqual([self.adapter sectionControllerForObject:two].section, 2); + XCTAssertEqual([self.adapter sectionControllerForObject:three].section, 3); XCTAssertTrue([self.adapter sectionControllerForObject:three].isLastSection); } @@ -1130,27 +1130,27 @@ - (void)test_whenRemovingFromHead_thatAllSectionControllerIndexesUpdateCorrectly [self.adapter performUpdatesAnimated:NO completion:nil]; IGListSectionController *zeroController = [self.adapter sectionControllerForSection:0]; - XCTAssertEqual(zeroController.sectionIndex, 0); + XCTAssertEqual(zeroController.section, 0); XCTAssertTrue(zeroController.isFirstSection); IGListSectionController *oneController = [self.adapter sectionControllerForSection:1]; - XCTAssertEqual(oneController.sectionIndex, 1); + XCTAssertEqual(oneController.section, 1); XCTAssertFalse(oneController.isFirstSection); IGListSectionController *threeController = [self.adapter sectionControllerForSection:3]; - XCTAssertEqual(threeController.sectionIndex, 3); + XCTAssertEqual(threeController.section, 3); XCTAssertTrue(threeController.isLastSection); self.dataSource.objects = @[one, two, three]; [self.adapter performUpdatesAnimated:NO completion:nil]; - XCTAssertEqual(zeroController.sectionIndex, NSNotFound); + XCTAssertEqual(zeroController.section, NSNotFound); XCTAssertFalse(zeroController.isFirstSection); - XCTAssertEqual(oneController.sectionIndex, 0); + XCTAssertEqual(oneController.section, 0); XCTAssertTrue(oneController.isFirstSection); - XCTAssertEqual(threeController.sectionIndex, 2); + XCTAssertEqual(threeController.section, 2); XCTAssertTrue(threeController.isLastSection); } @@ -1163,31 +1163,31 @@ - (void)test_whenRemovingFromMiddle_thatAllSectionControllerIndexesUpdateCorrect [self.adapter performUpdatesAnimated:NO completion:nil]; IGListSectionController *zeroController = [self.adapter sectionControllerForSection:0]; - XCTAssertEqual(zeroController.sectionIndex, 0); + XCTAssertEqual(zeroController.section, 0); XCTAssertTrue(zeroController.isFirstSection); IGListSectionController *oneController = [self.adapter sectionControllerForSection:1]; - XCTAssertEqual(oneController.sectionIndex, 1); + XCTAssertEqual(oneController.section, 1); XCTAssertFalse(oneController.isFirstSection); IGListSectionController *threeController = [self.adapter sectionControllerForSection:3]; - XCTAssertEqual(threeController.sectionIndex, 3); + XCTAssertEqual(threeController.section, 3); XCTAssertTrue(threeController.isLastSection); self.dataSource.objects = @[zero, two, three]; [self.adapter performUpdatesAnimated:NO completion:nil]; - XCTAssertEqual(zeroController.sectionIndex, 0); + XCTAssertEqual(zeroController.section, 0); XCTAssertTrue(zeroController.isFirstSection); - XCTAssertEqual(oneController.sectionIndex, NSNotFound); + XCTAssertEqual(oneController.section, NSNotFound); XCTAssertFalse(oneController.isFirstSection); - XCTAssertEqual(threeController.sectionIndex, 2); + XCTAssertEqual(threeController.section, 2); XCTAssertTrue(threeController.isLastSection); } -- (void)test_withStrongRefToSectionController_thatAdapterSectionIndexIsZero_thatSectionControllerIndexDoesNotChange { +- (void)test_withStrongRefToSectionController_thatAdaptersectionIsZero_thatSectionControllerIndexDoesNotChange { IGListSectionController *sc = nil; // hold a weak reference to simulate what would happen to the collectionContext object on a section controller @@ -1207,11 +1207,10 @@ - (void)test_withStrongRefToSectionController_thatAdapterSectionIndexIsZero_that [adapter performUpdatesAnimated:NO completion:nil]; sc = [adapter sectionControllerForSection:1]; - XCTAssertEqual(sc.sectionIndex, 1); + XCTAssertEqual(sc.section, 1); } - XCTAssertEqual(sc.sectionIndex, NSNotFound); - // This will be 0 because wAdapter should be nil and so nil messaging will return 0 + XCTAssertEqual(sc.section, NSNotFound); XCTAssertEqual([wAdapter sectionForSectionController:sc], 0); } diff --git a/Tests/IGListSectionMapTests.m b/Tests/IGListSectionMapTests.m index 7cc4a873b..7f89f276f 100644 --- a/Tests/IGListSectionMapTests.m +++ b/Tests/IGListSectionMapTests.m @@ -92,13 +92,13 @@ - (void)test_whenUpdatingItems_thatSectionControllerIndexesAreUpdated { NSArray *objects = @[@0, @1, @2]; IGListTestSection *one = [IGListTestSection new]; - XCTAssertEqual(one.sectionIndex, NSNotFound); + XCTAssertEqual(one.section, NSNotFound); NSArray *sectionControllers = @[[IGListTestSection new], one, [IGListTestSection new]]; IGListSectionMap *map = [[IGListSectionMap alloc] initWithMapTable:[NSMapTable strongToStrongObjectsMapTable]]; [map updateWithObjects:objects sectionControllers:sectionControllers]; - XCTAssertEqual(one.sectionIndex, 1); + XCTAssertEqual(one.section, 1); XCTAssertFalse(one.isFirstSection); } diff --git a/Tests/IGListStackSectionControllerTests.m b/Tests/IGListStackSectionControllerTests.m index a817ec7d1..670167836 100644 --- a/Tests/IGListStackSectionControllerTests.m +++ b/Tests/IGListStackSectionControllerTests.m @@ -241,12 +241,12 @@ - (void)test_whenQueryingSectionControllerSection_thatSectionMatchesStackSection IGListTestSection *section21 = stack2.sectionControllers[0]; IGListTestSection *section22 = stack2.sectionControllers[1]; - XCTAssertEqual(stack1.sectionIndex, 0); - XCTAssertEqual(stack2.sectionIndex, 1); - XCTAssertEqual(section11.sectionIndex, 0); - XCTAssertEqual(section12.sectionIndex, 0); - XCTAssertEqual(section21.sectionIndex, 1); - XCTAssertEqual(section22.sectionIndex, 1); + XCTAssertEqual(stack1.section, 0); + XCTAssertEqual(stack2.section, 1); + XCTAssertEqual(section11.section, 0); + XCTAssertEqual(section12.section, 0); + XCTAssertEqual(section21.section, 1); + XCTAssertEqual(section22.section, 1); } - (void)test_whenReloadingItems_thatCollectionViewReloadsRelativeIndexPaths {