Replaces model(_:) with model(at:).

This commit is contained in:
Krunoslav Zaher 2016-10-20 00:41:07 +02:00
parent a7b8c11b40
commit 02c63a4f56
10 changed files with 16 additions and 31 deletions

View File

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

View File

@ -72,7 +72,7 @@ class RxCollectionViewReactiveArrayDataSource<Element>
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)

View File

@ -70,7 +70,7 @@ class RxTableViewReactiveArrayDataSource<Element>
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)

View File

@ -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<T>(_ indexPath: IndexPath) throws -> T {
public func model<T>(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
}

View File

@ -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<T>(_ indexPath: IndexPath) throws -> T {
public func model<T>(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)
}

View File

@ -115,7 +115,7 @@ public class CollectionViewSectionedDataSource<S: SectionModelType>
}
}
public func model(_ indexPath: IndexPath) throws -> Any {
public func model(at indexPath: IndexPath) throws -> Any {
return self[indexPath]
}

View File

@ -150,7 +150,7 @@ public class RxTableViewSectionedDataSource<S: SectionModelType>
}
}
public func model(_ indexPath: IndexPath) throws -> Any {
public func model(at indexPath: IndexPath) throws -> Any {
return self[indexPath]
}

View File

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

View File

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

View File

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