Skip to content

Commit b81db5e

Browse files
committed
Swift 3.0 simplifications.
1 parent 4350789 commit b81db5e

File tree

3 files changed

+13
-16
lines changed

3 files changed

+13
-16
lines changed

Sources/DataSources/Array+Extensions.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,18 @@ import Foundation
1212

1313
extension Array where Element: SectionModelType {
1414
mutating func moveFromSourceIndexPath(_ sourceIndexPath: IndexPath, destinationIndexPath: IndexPath) {
15-
let sourceSection = self[(sourceIndexPath as NSIndexPath).section]
15+
let sourceSection = self[sourceIndexPath.section]
1616
var sourceItems = sourceSection.items
1717

18-
let sourceItem = sourceItems.remove(at: (sourceIndexPath as NSIndexPath).item)
18+
let sourceItem = sourceItems.remove(at: sourceIndexPath.item)
1919

2020
let sourceSectionNew = Element(original: sourceSection, items: sourceItems)
21-
self[(sourceIndexPath as NSIndexPath).section] = sourceSectionNew
21+
self[sourceIndexPath.section] = sourceSectionNew
2222

23-
let destinationSection = self[(destinationIndexPath as NSIndexPath).section]
23+
let destinationSection = self[destinationIndexPath.section]
2424
var destinationItems = destinationSection.items
25-
destinationItems.insert(sourceItem, at: (destinationIndexPath as NSIndexPath).item)
25+
destinationItems.insert(sourceItem, at: destinationIndexPath.item)
2626

27-
self[(destinationIndexPath as NSIndexPath).section] = Element(original: destinationSection, items: destinationItems)
27+
self[destinationIndexPath.section] = Element(original: destinationSection, items: destinationItems)
2828
}
2929
}

Sources/DataSources/CollectionViewSectionedDataSource.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ public class CollectionViewSectionedDataSource<S: SectionModelType>
186186
}
187187

188188
override func _rx_collectionView(_ collectionView: UICollectionView, cellForItemAtIndexPath indexPath: IndexPath) -> UICollectionViewCell {
189-
precondition((indexPath as NSIndexPath).item < _sectionModels[(indexPath as NSIndexPath).section].items.count)
189+
precondition(indexPath.item < _sectionModels[indexPath.section].items.count)
190190

191191
return configureCell(self, collectionView, indexPath, itemAtIndexPath(indexPath))
192192
}

Sources/DataSources/TableViewSectionedDataSource.swift

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,11 @@ public class _TableViewSectionedDataSource
7777
func _sectionIndexTitlesForTableView(_ tableView: UITableView) -> [String]? {
7878
return nil
7979
}
80-
80+
8181
public func sectionIndexTitles(for tableView: UITableView) -> [String]? {
8282
return _sectionIndexTitlesForTableView(tableView)
8383
}
84-
#endif
8584

86-
#if os(iOS)
8785
func _rx_tableView(_ tableView: UITableView, sectionForSectionIndexTitle title: String, atIndex index: Int) -> Int {
8886
return 0
8987
}
@@ -142,13 +140,13 @@ public class RxTableViewSectionedDataSource<S: SectionModelType>
142140
}
143141

144142
public func itemAtIndexPath(_ indexPath: IndexPath) -> I {
145-
return self._sectionModels[(indexPath as NSIndexPath).section].items[(indexPath as NSIndexPath).item]
143+
return self._sectionModels[indexPath.section].items[indexPath.item]
146144
}
147145

148146
public func setItem(item: I, indexPath: IndexPath) {
149-
var section = self._sectionModels[(indexPath as NSIndexPath).section]
150-
section.items[(indexPath as NSIndexPath).item] = item
151-
self._sectionModels[(indexPath as NSIndexPath).section] = section
147+
var section = self._sectionModels[indexPath.section]
148+
section.items[indexPath.item] = item
149+
self._sectionModels[indexPath.section] = section
152150
}
153151

154152
public func modelAtIndexPath(_ indexPath: IndexPath) throws -> Any {
@@ -238,7 +236,7 @@ public class RxTableViewSectionedDataSource<S: SectionModelType>
238236
}
239237

240238
override func _rx_tableView(_ tableView: UITableView, cellForRowAtIndexPath indexPath: IndexPath) -> UITableViewCell {
241-
precondition((indexPath as NSIndexPath).item < _sectionModels[(indexPath as NSIndexPath).section].items.count)
239+
precondition(indexPath.item < _sectionModels[indexPath.section].items.count)
242240

243241
return configureCell(self, tableView, indexPath, itemAtIndexPath(indexPath))
244242
}
@@ -288,5 +286,4 @@ public class RxTableViewSectionedDataSource<S: SectionModelType>
288286
return section
289287
}
290288
#endif
291-
292289
}

0 commit comments

Comments
 (0)