From 02c63a4f56fbec5bb30a9e584db0d1b3d39c66dc Mon Sep 17 00:00:00 2001 From: Krunoslav Zaher Date: Thu, 20 Oct 2016 00:41:07 +0200 Subject: [PATCH] Replaces `model(_:)` with `model(at:)`. --- .../Common/SectionedViewDataSourceType.swift | 17 +---------------- ...xCollectionViewReactiveArrayDataSource.swift | 2 +- .../RxTableViewReactiveArrayDataSource.swift | 2 +- RxCocoa/iOS/UICollectionView+Rx.swift | 8 ++++---- RxCocoa/iOS/UITableView+Rx.swift | 8 ++++---- .../CollectionViewSectionedDataSource.swift | 2 +- .../TableViewSectionedDataSource.swift | 2 +- .../SectionedViewDataSourceMock.swift | 2 +- .../RxCocoaTests/UICollectionView+RxTests.swift | 2 +- Tests/RxCocoaTests/UITableView+RxTests.swift | 2 +- 10 files changed, 16 insertions(+), 31 deletions(-) diff --git a/RxCocoa/Common/SectionedViewDataSourceType.swift b/RxCocoa/Common/SectionedViewDataSourceType.swift index 1344951a..5f809ccc 100644 --- a/RxCocoa/Common/SectionedViewDataSourceType.swift +++ b/RxCocoa/Common/SectionedViewDataSourceType.swift @@ -20,20 +20,5 @@ public protocol SectionedViewDataSourceType { - parameter indexPath: Model index path - returns: Model at index path. */ - func model(_ indexPath: IndexPath) throws -> Any -} - -extension SectionedViewDataSourceType { - /** - Returns model at index path. - - In case data source doesn't contain any sections when this method is being called, `RxCocoaError.ItemsNotYetBound(object: self)` is thrown. - - - parameter indexPath: Model index path - - returns: Model at index path. - */ - @available(*, deprecated, renamed: "model(_:)") - func modelAtIndexPath(_ indexPath: IndexPath) throws -> Any { - return try self.model(indexPath) - } + func model(at indexPath: IndexPath) throws -> Any } diff --git a/RxCocoa/iOS/DataSources/RxCollectionViewReactiveArrayDataSource.swift b/RxCocoa/iOS/DataSources/RxCollectionViewReactiveArrayDataSource.swift index b8f139da..ab834977 100644 --- a/RxCocoa/iOS/DataSources/RxCollectionViewReactiveArrayDataSource.swift +++ b/RxCocoa/iOS/DataSources/RxCollectionViewReactiveArrayDataSource.swift @@ -72,7 +72,7 @@ class RxCollectionViewReactiveArrayDataSource return itemModels?[index] } - func model(_ indexPath: IndexPath) throws -> Any { + func model(at indexPath: IndexPath) throws -> Any { precondition(indexPath.section == 0) guard let item = itemModels?[indexPath.item] else { throw RxCocoaError.itemsNotYetBound(object: self) diff --git a/RxCocoa/iOS/DataSources/RxTableViewReactiveArrayDataSource.swift b/RxCocoa/iOS/DataSources/RxTableViewReactiveArrayDataSource.swift index db2db942..ec63f41f 100644 --- a/RxCocoa/iOS/DataSources/RxTableViewReactiveArrayDataSource.swift +++ b/RxCocoa/iOS/DataSources/RxTableViewReactiveArrayDataSource.swift @@ -70,7 +70,7 @@ class RxTableViewReactiveArrayDataSource return itemModels?[index] } - func model(_ indexPath: IndexPath) throws -> Any { + func model(at indexPath: IndexPath) throws -> Any { precondition(indexPath.section == 0) guard let item = itemModels?[indexPath.item] else { throw RxCocoaError.itemsNotYetBound(object: self) diff --git a/RxCocoa/iOS/UICollectionView+Rx.swift b/RxCocoa/iOS/UICollectionView+Rx.swift index a3087241..1dca7476 100644 --- a/RxCocoa/iOS/UICollectionView+Rx.swift +++ b/RxCocoa/iOS/UICollectionView+Rx.swift @@ -249,7 +249,7 @@ extension Reactive where Base: UICollectionView { return Observable.empty() } - return Observable.just(try view.rx.model(indexPath)) + return Observable.just(try view.rx.model(at: indexPath)) } return ControlEvent(events: source) @@ -272,7 +272,7 @@ extension Reactive where Base: UICollectionView { return Observable.empty() } - return Observable.just(try view.rx.model(indexPath)) + return Observable.just(try view.rx.model(at: indexPath)) } return ControlEvent(events: source) @@ -281,10 +281,10 @@ extension Reactive where Base: UICollectionView { /** Syncronous helper method for retrieving a model at indexPath through a reactive data source */ - public func model(_ indexPath: IndexPath) throws -> T { + public func model(at indexPath: IndexPath) throws -> T { let dataSource: SectionedViewDataSourceType = castOrFatalError(self.dataSource.forwardToDelegate(), message: "This method only works in case one of the `rx.itemsWith*` methods was used.") - let element = try dataSource.model(indexPath) + let element = try dataSource.model(at: indexPath) return element as! T } diff --git a/RxCocoa/iOS/UITableView+Rx.swift b/RxCocoa/iOS/UITableView+Rx.swift index 660cc954..4bee3087 100644 --- a/RxCocoa/iOS/UITableView+Rx.swift +++ b/RxCocoa/iOS/UITableView+Rx.swift @@ -333,7 +333,7 @@ extension Reactive where Base: UITableView { return Observable.empty() } - return Observable.just(try view.rx.model(indexPath)) + return Observable.just(try view.rx.model(at: indexPath)) } return ControlEvent(events: source) @@ -356,7 +356,7 @@ extension Reactive where Base: UITableView { return Observable.empty() } - return Observable.just(try view.rx.model(indexPath)) + return Observable.just(try view.rx.model(at: indexPath)) } return ControlEvent(events: source) @@ -365,10 +365,10 @@ extension Reactive where Base: UITableView { /** Synchronous helper method for retrieving a model at indexPath through a reactive data source. */ - public func model(_ indexPath: IndexPath) throws -> T { + public func model(at indexPath: IndexPath) throws -> T { let dataSource: SectionedViewDataSourceType = castOrFatalError(self.dataSource.forwardToDelegate(), message: "This method only works in case one of the `rx.items*` methods was used.") - let element = try dataSource.model(indexPath) + let element = try dataSource.model(at: indexPath) return castOrFatalError(element) } diff --git a/RxExample/RxDataSources/DataSources/CollectionViewSectionedDataSource.swift b/RxExample/RxDataSources/DataSources/CollectionViewSectionedDataSource.swift index b1f68b03..d6f729be 100644 --- a/RxExample/RxDataSources/DataSources/CollectionViewSectionedDataSource.swift +++ b/RxExample/RxDataSources/DataSources/CollectionViewSectionedDataSource.swift @@ -115,7 +115,7 @@ public class CollectionViewSectionedDataSource } } - public func model(_ indexPath: IndexPath) throws -> Any { + public func model(at indexPath: IndexPath) throws -> Any { return self[indexPath] } diff --git a/RxExample/RxDataSources/DataSources/TableViewSectionedDataSource.swift b/RxExample/RxDataSources/DataSources/TableViewSectionedDataSource.swift index 1d0ebb2b..cdac7944 100644 --- a/RxExample/RxDataSources/DataSources/TableViewSectionedDataSource.swift +++ b/RxExample/RxDataSources/DataSources/TableViewSectionedDataSource.swift @@ -150,7 +150,7 @@ public class RxTableViewSectionedDataSource } } - public func model(_ indexPath: IndexPath) throws -> Any { + public func model(at indexPath: IndexPath) throws -> Any { return self[indexPath] } diff --git a/Tests/RxCocoaTests/TestImplementations/SectionedViewDataSourceMock.swift b/Tests/RxCocoaTests/TestImplementations/SectionedViewDataSourceMock.swift index 5e8c298e..b24dac20 100644 --- a/Tests/RxCocoaTests/TestImplementations/SectionedViewDataSourceMock.swift +++ b/Tests/RxCocoaTests/TestImplementations/SectionedViewDataSourceMock.swift @@ -27,7 +27,7 @@ import UIKit super.init() } - func model(_ indexPath: IndexPath) throws -> Any { + func model(at indexPath: IndexPath) throws -> Any { return items![indexPath.item] } diff --git a/Tests/RxCocoaTests/UICollectionView+RxTests.swift b/Tests/RxCocoaTests/UICollectionView+RxTests.swift index 6ac0efa8..ad4f8b74 100644 --- a/Tests/RxCocoaTests/UICollectionView+RxTests.swift +++ b/Tests/RxCocoaTests/UICollectionView+RxTests.swift @@ -248,7 +248,7 @@ class UICollectionViewTests : RxTest { } let (collectionView, dataSourceSubscription) = createView() - let model: Int = try! collectionView.rx.model(IndexPath(item: 1, section: 0)) + let model: Int = try! collectionView.rx.model(at: IndexPath(item: 1, section: 0)) XCTAssertEqual(model, 2) diff --git a/Tests/RxCocoaTests/UITableView+RxTests.swift b/Tests/RxCocoaTests/UITableView+RxTests.swift index 7b5b79d5..b1332246 100644 --- a/Tests/RxCocoaTests/UITableView+RxTests.swift +++ b/Tests/RxCocoaTests/UITableView+RxTests.swift @@ -352,7 +352,7 @@ class UITableViewTests : RxTest { let (tableView, dataSourceSubscription) = createView() - let model: Int = try! tableView.rx.model(IndexPath(item: 1, section: 0)) + let model: Int = try! tableView.rx.model(at: IndexPath(item: 1, section: 0)) XCTAssertEqual(model, 2)