@@ -99,17 +99,24 @@ public class CollectionViewSectionedDataSource<S: SectionModelType>
99
99
return _sectionModels. map { Section ( original: $0. model, items: $0. items) }
100
100
}
101
101
102
- public func sectionAtIndex ( _ section: Int ) -> S {
102
+ public subscript ( section: Int ) -> S {
103
103
let sectionModel = self . _sectionModels [ section]
104
104
return S ( original: sectionModel. model, items: sectionModel. items)
105
105
}
106
106
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
+ }
109
116
}
110
117
111
- public func modelAtIndexPath ( _ indexPath: IndexPath ) throws -> Any {
112
- return itemAtIndexPath ( indexPath)
118
+ public func model ( _ indexPath: IndexPath ) throws -> Any {
119
+ return self [ indexPath]
113
120
}
114
121
115
122
public func setSections( _ sections: [ S ] ) {
@@ -188,7 +195,7 @@ public class CollectionViewSectionedDataSource<S: SectionModelType>
188
195
override func _rx_collectionView( _ collectionView: UICollectionView , cellForItemAtIndexPath indexPath: IndexPath ) -> UICollectionViewCell {
189
196
precondition ( indexPath. item < _sectionModels [ indexPath. section] . items. count)
190
197
191
- return configureCell ( self , collectionView, indexPath, itemAtIndexPath ( indexPath) )
198
+ return configureCell ( self , collectionView, indexPath, self [ indexPath] )
192
199
}
193
200
194
201
override func _rx_collectionView( _ collectionView: UICollectionView , viewForSupplementaryElementOfKind kind: String , atIndexPath indexPath: IndexPath ) -> UICollectionReusableView {
0 commit comments