Skip to content

Commit ba1508d

Browse files
committed
Makes data sources open. #68
1 parent 592d736 commit ba1508d

6 files changed

+48
-52
lines changed

Example/Example1_CustomizationUsingTableViewDelegate.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ extension CustomizationUsingTableViewDelegate : UITableViewDelegate {
8383
// you can also fetch item
8484
guard let item = dataSource?[indexPath],
8585
// .. or section and customize what you like
86-
let _ = dataSource?.sectionAtIndex(indexPath.section)
86+
let _ = dataSource?[indexPath.section]
8787
else {
8888
return 0.0
8989
}

Example/Example2_RandomizedSectionsAnimation.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ extension ViewController {
9393
}
9494

9595
dataSource.titleForHeaderInSection = { (ds, section) -> String? in
96-
return ds.sectionAtIndex(section).header
96+
return ds[section].header
9797
}
9898
}
9999

Example/Example3_TableViewEditing.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class EditingExampleViewController: UIViewController {
7474
}
7575

7676
dataSource.titleForHeaderInSection = { (ds, section) -> String? in
77-
return ds.sectionAtIndex(section).header
77+
return ds[section].header
7878
}
7979

8080
dataSource.canEditRowAtIndexPath = { _ in

Podfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ SPEC CHECKSUMS:
2929

3030
PODFILE CHECKSUM: 43bd333b10d7dfc5029b1ff3167bbf181e4f3f65
3131

32-
COCOAPODS: 1.1.0.beta.2
32+
COCOAPODS: 1.1.0.rc.2

Sources/DataSources/CollectionViewSectionedDataSource.swift

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import UIKit
1212
import RxCocoa
1313
#endif
1414

15-
public class _CollectionViewSectionedDataSource
15+
open class _CollectionViewSectionedDataSource
1616
: NSObject
1717
, UICollectionViewDataSource {
1818

@@ -65,7 +65,7 @@ public class _CollectionViewSectionedDataSource
6565

6666
}
6767

68-
public class CollectionViewSectionedDataSource<S: SectionModelType>
68+
open class CollectionViewSectionedDataSource<S: SectionModelType>
6969
: _CollectionViewSectionedDataSource
7070
, SectionedViewDataSourceType {
7171
public typealias I = S.Item
@@ -99,12 +99,12 @@ public class CollectionViewSectionedDataSource<S: SectionModelType>
9999
return _sectionModels.map { Section(original: $0.model, items: $0.items) }
100100
}
101101

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

107-
public subscript(indexPath: IndexPath) -> I {
107+
open subscript(indexPath: IndexPath) -> I {
108108
get {
109109
return self._sectionModels[indexPath.section].items[indexPath.item]
110110
}
@@ -115,48 +115,38 @@ public class CollectionViewSectionedDataSource<S: SectionModelType>
115115
}
116116
}
117117

118-
public func model(_ indexPath: IndexPath) throws -> Any {
118+
open func model(_ indexPath: IndexPath) throws -> Any {
119119
return self[indexPath]
120120
}
121121

122122
public func setSections(_ sections: [S]) {
123123
self._sectionModels = sections.map { SectionModelSnapshot(model: $0, items: $0.items) }
124124
}
125125

126-
public var configureCell: CellFactory! = nil {
126+
open var configureCell: CellFactory! = nil {
127127
didSet {
128128
#if DEBUG
129129
ensureNotMutatedAfterBinding()
130130
#endif
131131
}
132132
}
133133

134-
@available(*, deprecated:0.8.1, renamed:"configureCell")
135-
public var cellFactory: CellFactory! {
136-
get {
137-
return self.configureCell
138-
}
139-
set {
140-
self.configureCell = newValue
141-
}
142-
}
143-
144-
public var supplementaryViewFactory: SupplementaryViewFactory {
134+
open var supplementaryViewFactory: SupplementaryViewFactory {
145135
didSet {
146136
#if DEBUG
147137
ensureNotMutatedAfterBinding()
148138
#endif
149139
}
150140
}
151141

152-
public var moveItem: ((CollectionViewSectionedDataSource<S>, _ sourceIndexPath:IndexPath, _ destinationIndexPath:IndexPath) -> Void)? {
142+
open var moveItem: ((CollectionViewSectionedDataSource<S>, _ sourceIndexPath:IndexPath, _ destinationIndexPath:IndexPath) -> Void)? {
153143
didSet {
154144
#if DEBUG
155145
ensureNotMutatedAfterBinding()
156146
#endif
157147
}
158148
}
159-
public var canMoveItemAtIndexPath: ((CollectionViewSectionedDataSource<S>, IndexPath) -> Bool)? {
149+
open var canMoveItemAtIndexPath: ((CollectionViewSectionedDataSource<S>, IndexPath) -> Bool)? {
160150
didSet {
161151
#if DEBUG
162152
ensureNotMutatedAfterBinding()
@@ -184,33 +174,33 @@ public class CollectionViewSectionedDataSource<S: SectionModelType>
184174

185175
// UICollectionViewDataSource
186176

187-
override func _numberOfSectionsInCollectionView(_ collectionView: UICollectionView) -> Int {
177+
open override func _numberOfSectionsInCollectionView(_ collectionView: UICollectionView) -> Int {
188178
return _sectionModels.count
189179
}
190180

191-
override func _rx_collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
181+
open override func _rx_collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
192182
return _sectionModels[section].items.count
193183
}
194184

195-
override func _rx_collectionView(_ collectionView: UICollectionView, cellForItemAtIndexPath indexPath: IndexPath) -> UICollectionViewCell {
185+
open override func _rx_collectionView(_ collectionView: UICollectionView, cellForItemAtIndexPath indexPath: IndexPath) -> UICollectionViewCell {
196186
precondition(indexPath.item < _sectionModels[indexPath.section].items.count)
197187

198188
return configureCell(self, collectionView, indexPath, self[indexPath])
199189
}
200190

201-
override func _rx_collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, atIndexPath indexPath: IndexPath) -> UICollectionReusableView {
191+
open override func _rx_collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, atIndexPath indexPath: IndexPath) -> UICollectionReusableView {
202192
return supplementaryViewFactory(self, collectionView, kind, indexPath)
203193
}
204194

205-
override func _rx_collectionView(_ collectionView: UICollectionView, canMoveItemAtIndexPath indexPath: IndexPath) -> Bool {
195+
open override func _rx_collectionView(_ collectionView: UICollectionView, canMoveItemAtIndexPath indexPath: IndexPath) -> Bool {
206196
guard let canMoveItem = canMoveItemAtIndexPath?(self, indexPath) else {
207197
return super._rx_collectionView(collectionView, canMoveItemAtIndexPath: indexPath)
208198
}
209199

210200
return canMoveItem
211201
}
212202

213-
override func _rx_collectionView(_ collectionView: UICollectionView, moveItemAtIndexPath sourceIndexPath: IndexPath, toIndexPath destinationIndexPath: IndexPath) {
203+
open override func _rx_collectionView(_ collectionView: UICollectionView, moveItemAtIndexPath sourceIndexPath: IndexPath, toIndexPath destinationIndexPath: IndexPath) {
214204
self._sectionModels.moveFromSourceIndexPath(sourceIndexPath, destinationIndexPath: destinationIndexPath)
215205
self.moveItem?(self, sourceIndexPath, destinationIndexPath)
216206
}

Sources/DataSources/TableViewSectionedDataSource.swift

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import RxCocoa
1313
#endif
1414

1515
// objc monkey business
16-
public class _TableViewSectionedDataSource
16+
open class _TableViewSectionedDataSource
1717
: NSObject
1818
, UITableViewDataSource {
1919

@@ -100,7 +100,7 @@ public class _TableViewSectionedDataSource
100100

101101
}
102102

103-
public class TableViewSectionedDataSource<S: SectionModelType>
103+
open class TableViewSectionedDataSource<S: SectionModelType>
104104
: _TableViewSectionedDataSource
105105
, SectionedViewDataSourceType {
106106

@@ -134,12 +134,18 @@ public class TableViewSectionedDataSource<S: SectionModelType>
134134
return _sectionModels.map { Section(original: $0.model, items: $0.items) }
135135
}
136136

137-
public func sectionAtIndex(_ section: Int) -> S {
137+
@available(*, deprecated, renamed: "subscript(section:)")
138+
open func sectionAtIndex(_ section: Int) -> S {
138139
let sectionModel = _sectionModels[section]
139140
return Section(original: sectionModel.model, items: sectionModel.items)
140141
}
141142

142-
public subscript(indexPath: IndexPath) -> I {
143+
open subscript(section: Int) -> S {
144+
let sectionModel = self._sectionModels[section]
145+
return S(original: sectionModel.model, items: sectionModel.items)
146+
}
147+
148+
open subscript(indexPath: IndexPath) -> I {
143149
get {
144150
return self._sectionModels[indexPath.section].items[indexPath.item]
145151
}
@@ -150,63 +156,63 @@ public class TableViewSectionedDataSource<S: SectionModelType>
150156
}
151157
}
152158

153-
public func model(_ indexPath: IndexPath) throws -> Any {
159+
open func model(_ indexPath: IndexPath) throws -> Any {
154160
return self[indexPath]
155161
}
156162

157163
public func setSections(_ sections: [S]) {
158164
self._sectionModels = sections.map { SectionModelSnapshot(model: $0, items: $0.items) }
159165
}
160166

161-
public var configureCell: CellFactory! = nil {
167+
open var configureCell: CellFactory! = nil {
162168
didSet {
163169
#if DEBUG
164170
ensureNotMutatedAfterBinding()
165171
#endif
166172
}
167173
}
168174

169-
public var titleForHeaderInSection: ((TableViewSectionedDataSource<S>, Int) -> String?)? {
175+
open var titleForHeaderInSection: ((TableViewSectionedDataSource<S>, Int) -> String?)? {
170176
didSet {
171177
#if DEBUG
172178
ensureNotMutatedAfterBinding()
173179
#endif
174180
}
175181
}
176-
public var titleForFooterInSection: ((TableViewSectionedDataSource<S>, Int) -> String?)? {
182+
open var titleForFooterInSection: ((TableViewSectionedDataSource<S>, Int) -> String?)? {
177183
didSet {
178184
#if DEBUG
179185
ensureNotMutatedAfterBinding()
180186
#endif
181187
}
182188
}
183189

184-
public var canEditRowAtIndexPath: ((TableViewSectionedDataSource<S>, IndexPath) -> Bool)? {
190+
open var canEditRowAtIndexPath: ((TableViewSectionedDataSource<S>, IndexPath) -> Bool)? {
185191
didSet {
186192
#if DEBUG
187193
ensureNotMutatedAfterBinding()
188194
#endif
189195
}
190196
}
191-
public var canMoveRowAtIndexPath: ((TableViewSectionedDataSource<S>, IndexPath) -> Bool)? {
197+
open var canMoveRowAtIndexPath: ((TableViewSectionedDataSource<S>, IndexPath) -> Bool)? {
192198
didSet {
193199
#if DEBUG
194200
ensureNotMutatedAfterBinding()
195201
#endif
196202
}
197203
}
198204

199-
public var rowAnimation: UITableViewRowAnimation = .automatic
205+
open var rowAnimation: UITableViewRowAnimation = .automatic
200206

201207
#if os(iOS)
202-
public var sectionIndexTitles: ((TableViewSectionedDataSource<S>) -> [String]?)? {
208+
open var sectionIndexTitles: ((TableViewSectionedDataSource<S>) -> [String]?)? {
203209
didSet {
204210
#if DEBUG
205211
ensureNotMutatedAfterBinding()
206212
#endif
207213
}
208214
}
209-
public var sectionForSectionIndexTitle:((TableViewSectionedDataSource<S>, _ title: String, _ index: Int) -> Int)? {
215+
open var sectionForSectionIndexTitle:((TableViewSectionedDataSource<S>, _ title: String, _ index: Int) -> Int)? {
210216
didSet {
211217
#if DEBUG
212218
ensureNotMutatedAfterBinding()
@@ -228,58 +234,58 @@ public class TableViewSectionedDataSource<S: SectionModelType>
228234

229235
// UITableViewDataSource
230236

231-
override func _numberOfSectionsInTableView(_ tableView: UITableView) -> Int {
237+
open override func _numberOfSectionsInTableView(_ tableView: UITableView) -> Int {
232238
return _sectionModels.count
233239
}
234240

235-
override func _rx_tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
241+
open override func _rx_tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
236242
return _sectionModels[section].items.count
237243
}
238244

239-
override func _rx_tableView(_ tableView: UITableView, cellForRowAtIndexPath indexPath: IndexPath) -> UITableViewCell {
245+
open override func _rx_tableView(_ tableView: UITableView, cellForRowAtIndexPath indexPath: IndexPath) -> UITableViewCell {
240246
precondition(indexPath.item < _sectionModels[indexPath.section].items.count)
241247

242248
return configureCell(self, tableView, indexPath, self[indexPath])
243249
}
244250

245-
override func _rx_tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
251+
open override func _rx_tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
246252
return titleForHeaderInSection?(self, section)
247253
}
248254

249-
override func _rx_tableView(_ tableView: UITableView, titleForFooterInSection section: Int) -> String? {
255+
open override func _rx_tableView(_ tableView: UITableView, titleForFooterInSection section: Int) -> String? {
250256
return titleForFooterInSection?(self, section)
251257
}
252258

253-
override func _rx_tableView(_ tableView: UITableView, canEditRowAtIndexPath indexPath: IndexPath) -> Bool {
259+
open override func _rx_tableView(_ tableView: UITableView, canEditRowAtIndexPath indexPath: IndexPath) -> Bool {
254260
guard let canEditRow = canEditRowAtIndexPath?(self, indexPath) else {
255261
return super._rx_tableView(tableView, canEditRowAtIndexPath: indexPath)
256262
}
257263

258264
return canEditRow
259265
}
260266

261-
override func _rx_tableView(_ tableView: UITableView, canMoveRowAtIndexPath indexPath: IndexPath) -> Bool {
267+
open override func _rx_tableView(_ tableView: UITableView, canMoveRowAtIndexPath indexPath: IndexPath) -> Bool {
262268
guard let canMoveRow = canMoveRowAtIndexPath?(self, indexPath) else {
263269
return super._rx_tableView(tableView, canMoveRowAtIndexPath: indexPath)
264270
}
265271

266272
return canMoveRow
267273
}
268274

269-
override func _rx_tableView(_ tableView: UITableView, moveRowAtIndexPath sourceIndexPath: IndexPath, toIndexPath destinationIndexPath: IndexPath) {
275+
open override func _rx_tableView(_ tableView: UITableView, moveRowAtIndexPath sourceIndexPath: IndexPath, toIndexPath destinationIndexPath: IndexPath) {
270276
self._sectionModels.moveFromSourceIndexPath(sourceIndexPath, destinationIndexPath: destinationIndexPath)
271277
}
272278

273279
#if os(iOS)
274-
override func _sectionIndexTitlesForTableView(_ tableView: UITableView) -> [String]? {
280+
open override func _sectionIndexTitlesForTableView(_ tableView: UITableView) -> [String]? {
275281
guard let titles = sectionIndexTitles?(self) else {
276282
return super._sectionIndexTitlesForTableView(tableView)
277283
}
278284

279285
return titles
280286
}
281287

282-
override func _rx_tableView(_ tableView: UITableView, sectionForSectionIndexTitle title: String, atIndex index: Int) -> Int {
288+
open override func _rx_tableView(_ tableView: UITableView, sectionForSectionIndexTitle title: String, atIndex index: Int) -> Int {
283289
guard let section = sectionForSectionIndexTitle?(self, title, index) else {
284290
return super._rx_tableView(tableView, sectionForSectionIndexTitle: title, atIndex: index)
285291
}

0 commit comments

Comments
 (0)