Skip to content

Commit 4b664f4

Browse files
committed
Modernizations.
1 parent 979b92c commit 4b664f4

File tree

2 files changed

+25
-17
lines changed

2 files changed

+25
-17
lines changed

Sources/DataSources/CollectionViewSectionedDataSource.swift

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,17 +99,24 @@ public class CollectionViewSectionedDataSource<S: SectionModelType>
9999
return _sectionModels.map { Section(original: $0.model, items: $0.items) }
100100
}
101101

102-
public func sectionAtIndex(_ section: Int) -> S {
102+
public subscript(section: Int) -> S {
103103
let sectionModel = self._sectionModels[section]
104104
return S(original: sectionModel.model, items: sectionModel.items)
105105
}
106106

107-
public func itemAtIndexPath(_ indexPath: IndexPath) -> I {
108-
return self._sectionModels[indexPath.section].items[indexPath.item]
107+
public subscript(indexPath: IndexPath) -> I {
108+
get {
109+
return self._sectionModels[indexPath.section].items[indexPath.item]
110+
}
111+
set(item) {
112+
var section = self._sectionModels[indexPath.section]
113+
section.items[indexPath.item] = item
114+
self._sectionModels[indexPath.section] = section
115+
}
109116
}
110117

111-
public func modelAtIndexPath(_ indexPath: IndexPath) throws -> Any {
112-
return itemAtIndexPath(indexPath)
118+
public func model(_ indexPath: IndexPath) throws -> Any {
119+
return self[indexPath]
113120
}
114121

115122
public func setSections(_ sections: [S]) {
@@ -188,7 +195,7 @@ public class CollectionViewSectionedDataSource<S: SectionModelType>
188195
override func _rx_collectionView(_ collectionView: UICollectionView, cellForItemAtIndexPath indexPath: IndexPath) -> UICollectionViewCell {
189196
precondition(indexPath.item < _sectionModels[indexPath.section].items.count)
190197

191-
return configureCell(self, collectionView, indexPath, itemAtIndexPath(indexPath))
198+
return configureCell(self, collectionView, indexPath, self[indexPath])
192199
}
193200

194201
override func _rx_collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, atIndexPath indexPath: IndexPath) -> UICollectionReusableView {

Sources/DataSources/TableViewSectionedDataSource.swift

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -139,18 +139,19 @@ public class RxTableViewSectionedDataSource<S: SectionModelType>
139139
return Section(original: sectionModel.model, items: sectionModel.items)
140140
}
141141

142-
public func itemAtIndexPath(_ indexPath: IndexPath) -> I {
143-
return self._sectionModels[indexPath.section].items[indexPath.item]
144-
}
145-
146-
public func setItem(item: I, indexPath: IndexPath) {
147-
var section = self._sectionModels[indexPath.section]
148-
section.items[indexPath.item] = item
149-
self._sectionModels[indexPath.section] = section
142+
public subscript(indexPath: IndexPath) -> I {
143+
get {
144+
return self._sectionModels[indexPath.section].items[indexPath.item]
145+
}
146+
set(item) {
147+
var section = self._sectionModels[indexPath.section]
148+
section.items[indexPath.item] = item
149+
self._sectionModels[indexPath.section] = section
150+
}
150151
}
151152

152-
public func modelAtIndexPath(_ indexPath: IndexPath) throws -> Any {
153-
return itemAtIndexPath(indexPath)
153+
public func model(_ indexPath: IndexPath) throws -> Any {
154+
return self[indexPath]
154155
}
155156

156157
public func setSections(_ sections: [S]) {
@@ -238,7 +239,7 @@ public class RxTableViewSectionedDataSource<S: SectionModelType>
238239
override func _rx_tableView(_ tableView: UITableView, cellForRowAtIndexPath indexPath: IndexPath) -> UITableViewCell {
239240
precondition(indexPath.item < _sectionModels[indexPath.section].items.count)
240241

241-
return configureCell(self, tableView, indexPath, itemAtIndexPath(indexPath))
242+
return configureCell(self, tableView, indexPath, self[indexPath])
242243
}
243244

244245
override func _rx_tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {

0 commit comments

Comments
 (0)