Adaptations for Swift 3.0.

This commit is contained in:
Krunoslav Zaher 2016-07-10 14:55:18 +02:00
parent b47ce13eae
commit 9cac0cc234
12 changed files with 38 additions and 38 deletions

View File

@ -323,13 +323,13 @@ extension UITableView {
public func rx_itemsWithDataSource(dataSource: DataSource)(source: O) -> Disposable {}
public var rx_itemSelected: ControlEvent<NSIndexPath> {}
public var rx_itemSelected: ControlEvent<IndexPath> {}
public var rx_itemDeselected: ControlEvent<NSIndexPath> {}
public var rx_itemDeselected: ControlEvent<IndexPath> {}
public var rx_itemInserted: ControlEvent<NSIndexPath> {}
public var rx_itemInserted: ControlEvent<IndexPath> {}
public var rx_itemDeleted: ControlEvent<NSIndexPath> {}
public var rx_itemDeleted: ControlEvent<IndexPath> {}
public var rx_itemMoved: ControlEvent<ItemMovedEvent> {}
@ -355,9 +355,9 @@ extension UICollectionView {
public func rx_itemsWithDataSource(dataSource: DataSource)(source: O) -> Disposable {}
public var rx_itemSelected: ControlEvent<NSIndexPath> {}
public var rx_itemSelected: ControlEvent<IndexPath> {}
public var rx_itemDeselected: ControlEvent<NSIndexPath> {}
public var rx_itemDeselected: ControlEvent<IndexPath> {}
// This method only works in case one of the `rx_itemsWith*` methods was used, or data source implements `SectionedViewDataSourceType`
public func rx_modelSelected<T>(modelType: T.Type) -> ControlEvent<T> {}

View File

@ -73,8 +73,8 @@ class RxCollectionViewReactiveArrayDataSource<Element>
}
func modelAtIndexPath(_ indexPath: IndexPath) throws -> Any {
precondition((indexPath as NSIndexPath).section == 0)
guard let item = itemModels?[(indexPath as NSIndexPath).item] else {
precondition(indexPath.section == 0)
guard let item = itemModels?[indexPath.item] else {
throw RxCocoaError.itemsNotYetBound(object: self)
}
return item
@ -93,7 +93,7 @@ class RxCollectionViewReactiveArrayDataSource<Element>
}
override func _collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
return cellFactory(collectionView, (indexPath as NSIndexPath).item, itemModels![(indexPath as NSIndexPath).item])
return cellFactory(collectionView, indexPath.item, itemModels![indexPath.item])
}
// reactive

View File

@ -71,8 +71,8 @@ class RxTableViewReactiveArrayDataSource<Element>
}
func modelAtIndexPath(_ indexPath: IndexPath) throws -> Any {
precondition((indexPath as NSIndexPath).section == 0)
guard let item = itemModels?[(indexPath as NSIndexPath).item] else {
precondition(indexPath.section == 0)
guard let item = itemModels?[indexPath.item] else {
throw RxCocoaError.itemsNotYetBound(object: self)
}
return item
@ -89,7 +89,7 @@ class RxTableViewReactiveArrayDataSource<Element>
}
override func _tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
return cellFactory(tableView, (indexPath as NSIndexPath).item, itemModels![(indexPath as NSIndexPath).row])
return cellFactory(tableView, indexPath.item, itemModels![indexPath.row])
}
// reactive

View File

@ -35,7 +35,7 @@ extension UICollectionView {
items
.bindTo(collectionView.rx_itemsWithCellFactory) { (collectionView, row, element) in
let indexPath = NSIndexPath(forItem: row, inSection: 0)
let indexPath = IndexPath(forItem: row, inSection: 0)
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath) as! NumberCell
cell.value?.text = "\(element) @ \(row)"
return cell

View File

@ -12,18 +12,18 @@ import Foundation
extension Array where Element: SectionModelType {
mutating func moveFromSourceIndexPath(_ sourceIndexPath: IndexPath, destinationIndexPath: IndexPath) {
let sourceSection = self[(sourceIndexPath as NSIndexPath).section]
let sourceSection = self[sourceIndexPath.section]
var sourceItems = sourceSection.items
let sourceItem = sourceItems.remove(at: (sourceIndexPath as NSIndexPath).item)
let sourceItem = sourceItems.remove(at: sourceIndexPath.item)
let sourceSectionNew = Element(original: sourceSection, items: sourceItems)
self[(sourceIndexPath as NSIndexPath).section] = sourceSectionNew
self[sourceIndexPath.section] = sourceSectionNew
let destinationSection = self[(destinationIndexPath as NSIndexPath).section]
let destinationSection = self[destinationIndexPath.section]
var destinationItems = destinationSection.items
destinationItems.insert(sourceItem, at: (destinationIndexPath as NSIndexPath).item)
destinationItems.insert(sourceItem, at: destinationIndexPath.item)
self[(destinationIndexPath as NSIndexPath).section] = Element(original: destinationSection, items: destinationItems)
self[destinationIndexPath.section] = Element(original: destinationSection, items: destinationItems)
}
}

View File

@ -71,7 +71,7 @@ public class CollectionViewSectionedDataSource<S: SectionModelType>
public typealias I = S.Item
public typealias Section = S
public typealias CellFactory = (CollectionViewSectionedDataSource<S>, UICollectionView, IndexPath, I) -> UICollectionViewCell
public typealias SupplementaryViewFactory = (CollectionViewSectionedDataSource<S>, UICollectionView, String, NSIndexPath) -> UICollectionReusableView
public typealias SupplementaryViewFactory = (CollectionViewSectionedDataSource<S>, UICollectionView, String, IndexPath) -> UICollectionReusableView
#if DEBUG
// If data source has already been bound, then mutating it
@ -105,7 +105,7 @@ public class CollectionViewSectionedDataSource<S: SectionModelType>
}
public func itemAtIndexPath(_ indexPath: IndexPath) -> I {
return self._sectionModels[(indexPath as NSIndexPath).section].items[(indexPath as NSIndexPath).item]
return self._sectionModels[indexPath.section].items[indexPath.item]
}
public func modelAtIndexPath(_ indexPath: IndexPath) throws -> Any {
@ -186,7 +186,7 @@ public class CollectionViewSectionedDataSource<S: SectionModelType>
}
override func _rx_collectionView(_ collectionView: UICollectionView, cellForItemAtIndexPath indexPath: IndexPath) -> UICollectionViewCell {
precondition((indexPath as NSIndexPath).item < _sectionModels[(indexPath as NSIndexPath).section].items.count)
precondition(indexPath.item < _sectionModels[indexPath.section].items.count)
return configureCell(self, collectionView, indexPath, itemAtIndexPath(indexPath))
}

View File

@ -138,13 +138,13 @@ public class RxTableViewSectionedDataSource<S: SectionModelType>
}
public func itemAtIndexPath(_ indexPath: IndexPath) -> I {
return self._sectionModels[(indexPath as NSIndexPath).section].items[(indexPath as NSIndexPath).item]
return self._sectionModels[indexPath.section].items[indexPath.item]
}
public func setItem(item: I, indexPath: IndexPath) {
var section = self._sectionModels[(indexPath as NSIndexPath).section]
section.items[(indexPath as NSIndexPath).item] = item
self._sectionModels[(indexPath as NSIndexPath).section] = section
var section = self._sectionModels[indexPath.section]
section.items[indexPath.item] = item
self._sectionModels[indexPath.section] = section
}
public func modelAtIndexPath(_ indexPath: IndexPath) throws -> Any {
@ -232,7 +232,7 @@ public class RxTableViewSectionedDataSource<S: SectionModelType>
}
override func _rx_tableView(_ tableView: UITableView, cellForRowAtIndexPath indexPath: IndexPath) -> UITableViewCell {
precondition((indexPath as NSIndexPath).item < _sectionModels[(indexPath as NSIndexPath).section].items.count)
precondition(indexPath.item < _sectionModels[indexPath.section].items.count)
return configureCell(self, tableView, indexPath, itemAtIndexPath(indexPath))
}

View File

@ -45,7 +45,7 @@ class SimpleTableViewExampleSectionedViewController
dataSource.configureCell = { (_, tv, indexPath, element) in
let cell = tv.dequeueReusableCell(withIdentifier: "Cell")!
cell.textLabel?.text = "\(element) @ row \((indexPath as NSIndexPath).row)"
cell.textLabel?.text = "\(element) @ row \(indexPath.row)"
return cell
}

View File

@ -152,7 +152,7 @@ class PartialUpdatesViewController : ViewController {
func skinCollectionViewDataSource(_ dataSource: CollectionViewSectionedDataSource<NumberSection>) {
dataSource.configureCell = { (_, cv, ip, i) in
let cell = cv.dequeueReusableCell(withReuseIdentifier: "Cell", for: ip as IndexPath) as! NumberCell
let cell = cv.dequeueReusableCell(withReuseIdentifier: "Cell", for: ip) as! NumberCell
cell.value!.text = "\(i)"
@ -160,9 +160,9 @@ class PartialUpdatesViewController : ViewController {
}
dataSource.supplementaryViewFactory = { (dataSource, cv, kind, ip) in
let section = cv.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "Section", for: ip as IndexPath) as! NumberSectionView
let section = cv.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "Section", for: ip) as! NumberSectionView
section.value!.text = "\(dataSource.sectionAtIndex((ip as NSIndexPath).section).model)"
section.value!.text = "\(dataSource.sectionAtIndex(ip.section).model)"
return section
}

View File

@ -33,13 +33,13 @@ struct TableViewEditingCommandsViewModel {
return TableViewEditingCommandsViewModel(favoriteUsers: favoriteUsers, users: users)
case let .deleteUser(indexPath):
var all = [self.favoriteUsers, self.users]
all[(indexPath as NSIndexPath).section].remove(at: (indexPath as NSIndexPath).row)
all[indexPath.section].remove(at: indexPath.row)
return TableViewEditingCommandsViewModel(favoriteUsers: all[0], users: all[1])
case let .moveUser(from, to):
var all = [self.favoriteUsers, self.users]
let user = all[(from as NSIndexPath).section][(from as NSIndexPath).row]
all[(from as NSIndexPath).section].remove(at: (from as NSIndexPath).row)
all[(to as NSIndexPath).section].insert(user, at: (to as NSIndexPath).row)
let user = all[from.section][from.row]
all[from.section].remove(at: from.row)
all[to.section].insert(user, at: to.row)
return TableViewEditingCommandsViewModel(favoriteUsers: all[0], users: all[1])
}

View File

@ -327,7 +327,7 @@ class MockThreeDSectionedViewProtocol : NSObject, ThreeDSectionedViewProtocol {
return 3
}
/*func threeDView(threeDView: ThreeDSectionedView, didGetXXX: NSIndexPath) {
/*func threeDView(threeDView: ThreeDSectionedView, didGetXXX: IndexPath) {
messages.append("didGetXXX")
}*/
@ -335,7 +335,7 @@ class MockThreeDSectionedViewProtocol : NSObject, ThreeDSectionedViewProtocol {
messages.append("didLearnSomething")
}
//optional func threeDView(threeDView: ThreeDSectionedView, didFallAsleep: NSIndexPath)
//optional func threeDView(threeDView: ThreeDSectionedView, didFallAsleep: IndexPath)
func threeDView(_ threeDView: ThreeDSectionedView, getMeSomeFood: IndexPath) -> Food {
messages.append("getMeSomeFood")
return Food()

View File

@ -28,7 +28,7 @@ import UIKit
}
func modelAtIndexPath(_ indexPath: IndexPath) throws -> Any {
return items![(indexPath as NSIndexPath).item]
return items![indexPath.item]
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {