From 6128b6f3c4e404f27f4ae790ee05cbc2415431ca Mon Sep 17 00:00:00 2001 From: Jesse Squires Date: Sun, 11 Dec 2016 11:21:35 -0800 Subject: [PATCH 1/4] make item(atIndexPath: ) public --- CHANGELOG.md | 23 ++++++++++++++++------- Source/DataSource.swift | 8 ++++++++ 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f4004fb..1dedf02 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,31 +4,40 @@ The changelog for `JSQDataSourcesKit`. Also see the [releases](https://github.co -------------------------------------- +6.1.0 +----- + +This release closes the [6.1.0 milestone](https://github.com/jessesquires/JSQDataSourcesKit/milestone/11). + +## New + +- Added new `DataSourceProtocol` extension convenience method `func item(atIndexPath indexPath: IndexPath) -> Item?`. + 6.0.0 ----- -This release closes the [6.0.0 milestone](https://github.com/jessesquires/JSQDataSourcesKit/issues?utf8=✓&q=milestone%3A6.0.0). +This release closes the [6.0.0 milestone](https://github.com/jessesquires/JSQDataSourcesKit/milestone/9). **Swift 3.0 now required.** 5.0.0 ----- -This release closes the [5.0.0 milestone](https://github.com/jessesquires/JSQDataSourcesKit/issues?utf8=✓&q=milestone%3A5.0.0). +This release closes the [5.0.0 milestone](https://github.com/jessesquires/JSQDataSourcesKit/milestone/8). **Swift 2.3 now required.** 4.0.1 ----- -This release closes the [4.0.1 milestone](https://github.com/jessesquires/JSQDataSourcesKit/issues?utf8=✓&q=milestone%3A4.0.1+). +This release closes the [4.0.1 milestone](https://github.com/jessesquires/JSQDataSourcesKit/milestone/10). - Fixed an issue with `carthage build` (#61, #62). Thanks @dcaunt! 4.0.0 ----- -This release closes the [4.0.0 milestone](https://github.com/jessesquires/JSQDataSourcesKit/issues?utf8=✓&q=milestone%3A4.0.0+). +This release closes the [4.0.0 milestone](https://github.com/jessesquires/JSQDataSourcesKit/milestone/7). This release is essentially a complete re-write of the library. If you are currently using this, migration to `4.0` will be pretty involved, but it will be worth it. The result is a *dramatically simpler* API. @@ -109,12 +118,12 @@ The `*FetchedResultsDelegateProvider` classes have been unified into a single cl 3.0.1 ----- -Bug fixes from the [3.0.1](https://github.com/jessesquires/JSQDataSourcesKit/issues?q=milestone%3A3.0.1) milestone. +Bug fixes from the [3.0.1](https://github.com/jessesquires/JSQDataSourcesKit/milestone/6) milestone. 3.0.0 ----- -This release closes the [3.0.0 milestone](https://github.com/jessesquires/JSQDataSourcesKit/issues?q=milestone%3A3.0.0). +This release closes the [3.0.0 milestone](https://github.com/jessesquires/JSQDataSourcesKit/milestone/4). >**NOTE: This is actually a minor update, but there are breaking changes. Thus, the major version bump.** @@ -171,7 +180,7 @@ In short, this release contains tons of refinements and fixes. The codebase is s ## Issues closed -Find the complete list of closed issues [here](https://github.com/jessesquires/JSQDataSourcesKit/issues?q=milestone%3A2.0.0+is%3Aclosed) for the 2.0.0 milestone. +Find the complete list of closed issues [here](https://github.com/jessesquires/JSQDataSourcesKit/milestone/3) for the 2.0.0 milestone. ## Documentation diff --git a/Source/DataSource.swift b/Source/DataSource.swift index de8eaf7..bb96cff 100644 --- a/Source/DataSource.swift +++ b/Source/DataSource.swift @@ -294,3 +294,11 @@ extension FetchedResultsController: DataSourceProtocol { return nil } } + +extension FetchedResultsController { + + /// :nodoc: + public func item(atIndexPath indexPath: IndexPath) -> Item? { + return object(at: indexPath) as? T + } +} From d7c8b2dab68ac4fb71ad219f0c1dcbad8bb5b33d Mon Sep 17 00:00:00 2001 From: Jesse Squires Date: Mon, 12 Dec 2016 07:53:50 -0800 Subject: [PATCH 2/4] s/T/Item --- Source/DataSource.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/DataSource.swift b/Source/DataSource.swift index bb96cff..6d17887 100644 --- a/Source/DataSource.swift +++ b/Source/DataSource.swift @@ -299,6 +299,6 @@ extension FetchedResultsController { /// :nodoc: public func item(atIndexPath indexPath: IndexPath) -> Item? { - return object(at: indexPath) as? T + return object(at: indexPath) as? Item } } From 9cfb6c6074d1acd99a0845db313d2db56b99506b Mon Sep 17 00:00:00 2001 From: Jesse Squires Date: Mon, 12 Dec 2016 08:21:27 -0800 Subject: [PATCH 3/4] tests --- Tests/DataSourceTests.swift | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/Tests/DataSourceTests.swift b/Tests/DataSourceTests.swift index 16b22e1..ffe2383 100644 --- a/Tests/DataSourceTests.swift +++ b/Tests/DataSourceTests.swift @@ -156,6 +156,27 @@ final class DataSourceTests: XCTestCase { XCTAssertEqual(frc[IndexPath(item: 0, section: 2)], redThings[0]) } + func test_thatFetchedResultsController_returnsExpectedData_atIndexPath() { + // GIVEN: a core data stack and objects in a context + let context = CoreDataStack(inMemory: true).context + let blueThings = generateThings(context, color: .Blue) + let greenThings = generateThings(context, color: .Green) + let redThings = generateThings(context, color: .Red) + + // GIVEN: a fetched results controller + let frc = FetchedResultsController(fetchRequest: Thing.newFetchRequest(), + managedObjectContext: context, + sectionNameKeyPath: "colorName", + cacheName: nil) + _ = try? frc.performFetch() + + // WHEN: we ask for an object + // THEN: we receive the exepected data + XCTAssertEqual(frc.item(atIndexPath: IndexPath(item: 1, section: 0)), blueThings[1]) + XCTAssertEqual(frc.item(atIndexPath: IndexPath(item: 2, section: 1)), greenThings[2]) + XCTAssertEqual(frc.item(atIndexPath: IndexPath(item: 0, section: 2)), redThings[0]) + } + func test_thatDataSource_returnsExpectedData_fromIntSubscript() { // GIVEN: a data source let sectionA = Section(items: FakeViewModel(), FakeViewModel(), headerTitle: "Header") @@ -236,4 +257,20 @@ final class DataSourceTests: XCTestCase { let removedItem = dataSource.remove(at: ip) XCTAssertEqual(removedItem, itemToRemove) } + + func test_thatDataSource_returnsItem_atIndexPath() { + // GIVEN: a data source + let model = FakeViewModel() + let sectionA = Section(items: FakeViewModel(), FakeViewModel(), headerTitle: "Header") + let sectionB = Section(items: FakeViewModel(), FakeViewModel(), footerTitle: "Footer") + let sectionC = Section(items: FakeViewModel(), FakeViewModel(), model) + let dataSource = DataSource(sections: sectionA, sectionB, sectionC) + + // WHEN: we ask for an item + let ip = IndexPath(item: 2, section: 2) + let item = dataSource.item(atIndexPath: ip) + + // THEN: we receive the exepected data + XCTAssertEqual(item, model) + } } From 3278d408bff781e32ecffb47755123ccb31ed015 Mon Sep 17 00:00:00 2001 From: Jesse Squires Date: Tue, 13 Dec 2016 10:27:27 -0800 Subject: [PATCH 4/4] fix tests --- Tests/DataSourceTests.swift | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/Tests/DataSourceTests.swift b/Tests/DataSourceTests.swift index ffe2383..0cde95f 100644 --- a/Tests/DataSourceTests.swift +++ b/Tests/DataSourceTests.swift @@ -247,15 +247,16 @@ final class DataSourceTests: XCTestCase { let sectionB = Section(items: FakeViewModel(), FakeViewModel(), footerTitle: "Footer") var dataSource = DataSource(sections: sectionA, sectionB) - // WHEN: we set an item at a specific index path + // WHEN: we remove an item at a specific index path let ip = IndexPath(item: 1, section: 0) - let itemToRemove = dataSource.item(atIndexPath: ip) - - // THEN: Check if an item exists at the specified indexPath .Then check if the removedItem is the expected item + let itemToRemove = dataSource.remove(at: ip) + + // THEN: the item is removed XCTAssertNotNil(itemToRemove) - - let removedItem = dataSource.remove(at: ip) - XCTAssertEqual(removedItem, itemToRemove) + XCTAssertEqual(dataSource.sections.count, 2) + XCTAssertEqual(dataSource.items(inSection: 0)?.count, 1) + XCTAssertEqual(dataSource.items(inSection: 1)?.count, 2) + XCTAssertEqual(sectionA.count, 2, "Original section should not be changed") } func test_thatDataSource_returnsItem_atIndexPath() {