Skip to content

Commit 789b3e4

Browse files
authored
Merge pull request #14 from skladek/develop
1.0.0 Release
2 parents 030e394 + e8db6d7 commit 789b3e4

File tree

9 files changed

+236
-48
lines changed

9 files changed

+236
-48
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,7 @@ fastlane/report.xml
6262
fastlane/Preview.html
6363
fastlane/screenshots
6464
fastlane/test_output
65+
66+
# Jazzy Documentation
67+
68+
docs/

.travis.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@ language: swift
22
osx_image: xcode8.3
33
script: fastlane test
44
xcode_project: SKTableViewDataSource.xcodeproj
5-
xcode_scheme: SKTableViewDataSource
5+
xcode_scheme: SKTableViewDataSource
6+
after_success:
7+
- bash <(curl -s https://codecov.io/bash)

README.md

Lines changed: 90 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,94 @@
11
# SKTableViewDataSource
22

33
![Travis Status](https://travis-ci.org/skladek/SKTableViewDataSource.svg?branch=master)
4+
![Codecov Status](https://img.shields.io/codecov/c/github/skladek/SKTableViewDataSource.svg)
5+
![Pod Version](https://img.shields.io/cocoapods/v/SKTableViewDataSource.svg)
6+
![Platform Status](https://img.shields.io/cocoapods/p/SKTableViewDataSource.svg)
7+
![License Status](https://img.shields.io/github/license/skladek/SKTableViewDataSource.svg)
48

5-
Provides a reusable object to handle the boiler plate logic for the UITableViewDataSource.
9+
SKTableViewDataSource provides an object to handle much of the standard UITableViewDataSource logic. It handles calculating row and section counts, retrieving cells, and provides methods for updating the underlying array powering the data source. Check out the SampleProject in the workspace to see some usage examples.
10+
11+
---
12+
13+
## Installation
14+
15+
### Cocoapods
16+
17+
Instalation is supported through Cocoapods. Add the following to your pod file for the target where you would like to use SKTableViewDataSource:
18+
19+
```
20+
pod 'SKTableViewDataSource'
21+
```
22+
23+
---
24+
25+
## Initialization
26+
27+
### Auto Cell Registration
28+
29+
The easiest way to initialize a TableViewDataSource object is to provide an array, cell class or nib, and a CellPresenter closure to handle styling the cell during `cellForRowAtIndexPath`. Cell registration will be handled by the `TableViewDataSource` object. The objects array can be a 1 or 2 dimensional array. A single dimension array will display as a single section table view. A 2 dimensional array will display with multiple sections.
30+
31+
32+
```
33+
import SKTableViewDataSource
34+
```
35+
36+
```
37+
let dataSource = TableViewDataSource(objects: array, cell: UITableViewCell.self, cellPresenter: { (cell, object) in
38+
cell.textLabel?.text = object
39+
})
40+
41+
tableview.dataSource = dataSource
42+
```
43+
44+
### Manual Cell Registration
45+
46+
If you require access to the cell's reuse identifier or require multiple cell types in your table view, you can choose to register the cells yourself.
47+
48+
49+
```
50+
import SKTableViewDataSource
51+
```
52+
```
53+
tableView.register(YourCellClass.self, forCellReuseIdentifier: "YourReuseIdentifier")
54+
55+
let dataSource = TableViewDataSource(objects: array, delegate: self) {
56+
cell.textLabel?.text = object.rawValue
57+
})
58+
59+
tableView.dataSource = dataSource
60+
```
61+
Note: If you choose to handle cell registration on your own, you must implement TableViewDataSourceDelegate's `cellForRowAtIndexPath` method and return a cell for each index path.
62+
63+
---
64+
65+
## CellPresenter
66+
67+
Each initialization method for auto cell registration has an optional `CellPresenter` closure. The closure returns two parameters: a cell and an object. This closure can be used to populate the cell with values from the object.
68+
69+
---
70+
71+
## TableViewDataSourceDelegate
72+
73+
`TableViewDataSource` has an optional delegate. This serves as a pass through for `UITableViewDataSource` methods. The delegate object can override any of the `TableViewDataSource` implementations by implementing the corresponding delegate method.
74+
75+
---
76+
77+
## Updating The Data Array
78+
79+
There are a handful of methods for manipulating the data in the array. Updating the data source will not trigger any sort of update in the table view. That must be handled by the developer.
80+
81+
### delete(indexPath:)
82+
This will delete the object at the provided index path.
83+
84+
### insert(indexPath:)
85+
This will insert the provided object at the provided index path.
86+
87+
### moveFrom(_:to:)
88+
This will move the object at the from index path to the to index path.
89+
90+
### object(indexPath:)
91+
This returns the object at the provided index path.
92+
93+
### setObjects(_:)
94+
This replaces the existing objects array with the provided objects array.

SKTableViewDataSource.podspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Pod::Spec.new do |spec|
22
spec.name = 'SKTableViewDataSource'
3-
spec.version = '0.0.3'
3+
spec.version = '1.0.0'
44
spec.license = 'MIT'
5-
spec.summary = 'An easier to configure data source for UITableView.'
5+
spec.summary = 'An easy to configure data source for UITableView.'
66
spec.homepage = 'https://github.com/skladek/SKTableViewDataSource'
77
spec.authors = { 'Sean Kladek' => 'skladek@gmail.com' }
88
spec.source = { :git => 'https://github.com/skladek/SKTableViewDataSource.git', :tag => spec.version }

SKTableViewDataSource.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
142B565B1EF76F8300FCAF4E /* TableViewDataSourceDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 142B565A1EF76F8300FCAF4E /* TableViewDataSourceDelegate.swift */; };
1011
1431B8931EEB094A00D767DA /* SKTableViewDataSource.h in Headers */ = {isa = PBXBuildFile; fileRef = 1431B88C1EEB094A00D767DA /* SKTableViewDataSource.h */; settings = {ATTRIBUTES = (Public, ); }; };
1112
1431B8941EEB094A00D767DA /* TableViewDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1431B88D1EEB094A00D767DA /* TableViewDataSource.swift */; };
1213
1431B8981EEB095700D767DA /* MockTableViewDataSourceDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1431B8901EEB094A00D767DA /* MockTableViewDataSourceDelegate.swift */; };
@@ -30,6 +31,7 @@
3031
/* Begin PBXFileReference section */
3132
0075FEEE5559F2C44A5DF8A3 /* Pods-SKTableViewDataSource.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SKTableViewDataSource.release.xcconfig"; path = "Pods/Target Support Files/Pods-SKTableViewDataSource/Pods-SKTableViewDataSource.release.xcconfig"; sourceTree = "<group>"; };
3233
0F2AE1C6EC26C45BF83967D4 /* Pods-SKTableViewDataSourceTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SKTableViewDataSourceTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-SKTableViewDataSourceTests/Pods-SKTableViewDataSourceTests.debug.xcconfig"; sourceTree = "<group>"; };
34+
142B565A1EF76F8300FCAF4E /* TableViewDataSourceDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TableViewDataSourceDelegate.swift; sourceTree = "<group>"; };
3335
1431B88B1EEB094A00D767DA /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
3436
1431B88C1EEB094A00D767DA /* SKTableViewDataSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SKTableViewDataSource.h; sourceTree = "<group>"; };
3537
1431B88D1EEB094A00D767DA /* TableViewDataSource.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TableViewDataSource.swift; sourceTree = "<group>"; };
@@ -72,6 +74,7 @@
7274
1431B88B1EEB094A00D767DA /* Info.plist */,
7375
1431B88C1EEB094A00D767DA /* SKTableViewDataSource.h */,
7476
1431B88D1EEB094A00D767DA /* TableViewDataSource.swift */,
77+
142B565A1EF76F8300FCAF4E /* TableViewDataSourceDelegate.swift */,
7578
);
7679
path = Source;
7780
sourceTree = "<group>";
@@ -338,6 +341,7 @@
338341
buildActionMask = 2147483647;
339342
files = (
340343
1431B8941EEB094A00D767DA /* TableViewDataSource.swift in Sources */,
344+
142B565B1EF76F8300FCAF4E /* TableViewDataSourceDelegate.swift in Sources */,
341345
);
342346
runOnlyForDeploymentPostprocessing = 0;
343347
};

Source/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<key>CFBundlePackageType</key>
1616
<string>FMWK</string>
1717
<key>CFBundleShortVersionString</key>
18-
<string>0.0.3</string>
18+
<string>1.0.0</string>
1919
<key>CFBundleVersion</key>
2020
<string>$(CURRENT_PROJECT_VERSION)</string>
2121
<key>NSPrincipalClass</key>

Source/TableViewDataSource.swift

Lines changed: 17 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -8,42 +8,7 @@
88

99
import UIKit
1010

11-
@objc
12-
public protocol TableViewDataSourceDelegate {
13-
@objc
14-
optional func numberOfSections(in tableView: UITableView) -> Int
15-
16-
@objc
17-
optional func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool
18-
19-
@objc
20-
optional func tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -> Bool
21-
22-
@objc
23-
optional func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell?
24-
25-
@objc
26-
optional func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath)
27-
28-
@objc
29-
optional func tableView(_ tableView: UITableView, moveRowAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath)
30-
31-
@objc
32-
optional func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
33-
34-
@objc
35-
optional func sectionIndexTitles(for tableView: UITableView) -> [String]?
36-
37-
@objc
38-
optional func tableView(_ tableView: UITableView, sectionForSectionIndexTitle title: String, at index: Int) -> Int
39-
40-
@objc
41-
optional func tableView(_ tableView: UITableView, titleForFooterInSection section: Int) -> String?
42-
43-
@objc
44-
optional func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String?
45-
}
46-
11+
/// Provides an object to act as a UITableViewDataSource.
4712
public class TableViewDataSource<T>: NSObject, UITableViewDataSource {
4813

4914
// MARK: Class Types
@@ -84,11 +49,10 @@ public class TableViewDataSource<T>: NSObject, UITableViewDataSource {
8449
/// - Parameters:
8550
/// - objects: The objects to be displayed in the table view.
8651
/// - delegate: The object acting as the delegate to the data source.
87-
/// - cellPresenter: An optional closure that can be used to inject view styling and further configuration.
88-
public convenience init(objects: [T]?, delegate: TableViewDataSourceDelegate, cellPresenter: CellPresenter? = nil) {
52+
public convenience init(objects: [T]?, delegate: TableViewDataSourceDelegate) {
8953
let wrappedObjects = TableViewDataSource.wrapObjects(objects)
9054

91-
self.init(objects: wrappedObjects, cellClass: nil, cellNib: nil, cellPresenter: cellPresenter)
55+
self.init(objects: wrappedObjects, cellClass: nil, cellNib: nil, cellPresenter: nil)
9256

9357
self.delegate = delegate
9458
}
@@ -99,9 +63,8 @@ public class TableViewDataSource<T>: NSObject, UITableViewDataSource {
9963
/// - Parameters:
10064
/// - objects: The objects to be displayed in the table view.
10165
/// - delegate: The object acting as the delegate to the data source.
102-
/// - cellPresenter: An optional closure that can be used to inject view styling and further configuration.
103-
public convenience init(objects: [[T]]?, delegate: TableViewDataSourceDelegate, cellPresenter: CellPresenter? = nil) {
104-
self.init(objects: objects, cellClass: nil, cellNib: nil, cellPresenter: cellPresenter)
66+
public convenience init(objects: [[T]]?, delegate: TableViewDataSourceDelegate) {
67+
self.init(objects: objects, cellClass: nil, cellNib: nil, cellPresenter: nil)
10568

10669
self.delegate = delegate
10770
}
@@ -157,7 +120,7 @@ public class TableViewDataSource<T>: NSObject, UITableViewDataSource {
157120
self.objects = objects ?? [[T]]()
158121
}
159122

160-
// MARK: Instance Methods
123+
// MARK: Public Methods
161124

162125
/// Deletes the object at the given index path
163126
///
@@ -261,6 +224,7 @@ public class TableViewDataSource<T>: NSObject, UITableViewDataSource {
261224

262225
// MARK: UITableViewDataSource Methods
263226

227+
/// UITableviewDataSource implementation.
264228
public func numberOfSections(in tableView: UITableView) -> Int {
265229
if let sections = delegate?.numberOfSections?(in: tableView) {
266230
return sections
@@ -269,18 +233,22 @@ public class TableViewDataSource<T>: NSObject, UITableViewDataSource {
269233
return objects.count
270234
}
271235

236+
/// UITableviewDataSource implementation.
272237
public func sectionIndexTitles(for tableView: UITableView) -> [String]? {
273238
return delegate?.sectionIndexTitles?(for: tableView)
274239
}
275240

241+
/// UITableviewDataSource implementation.
276242
public func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
277243
return delegate?.tableView?(tableView, canEditRowAt: indexPath) ?? false
278244
}
279245

246+
/// UITableviewDataSource implementation.
280247
public func tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -> Bool {
281248
return delegate?.tableView?(tableView, canMoveRowAt: indexPath) ?? true
282249
}
283250

251+
/// UITableviewDataSource implementation.
284252
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
285253
if let cell = delegate?.tableView?(tableView, cellForRowAt: indexPath) {
286254
return cell
@@ -296,14 +264,17 @@ public class TableViewDataSource<T>: NSObject, UITableViewDataSource {
296264
return cell
297265
}
298266

267+
/// UITableviewDataSource implementation.
299268
public func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
300269
delegate?.tableView?(tableView, commit: editingStyle, forRowAt: indexPath)
301270
}
302271

272+
/// UITableviewDataSource implementation.
303273
public func tableView(_ tableView: UITableView, moveRowAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath) {
304274
delegate?.tableView?(tableView, moveRowAt: sourceIndexPath, to: destinationIndexPath)
305275
}
306276

277+
/// UITableviewDataSource implementation.
307278
public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
308279
if let rows = delegate?.tableView?(tableView, numberOfRowsInSection: section) {
309280
return rows
@@ -315,10 +286,12 @@ public class TableViewDataSource<T>: NSObject, UITableViewDataSource {
315286
return section.count
316287
}
317288

289+
/// UITableviewDataSource implementation.
318290
public func tableView(_ tableView: UITableView, sectionForSectionIndexTitle title: String, at index: Int) -> Int {
319291
return delegate?.tableView?(tableView, sectionForSectionIndexTitle: title, at: index) ?? -1
320292
}
321293

294+
/// UITableviewDataSource implementation.
322295
public func tableView(_ tableView: UITableView, titleForFooterInSection section: Int) -> String? {
323296
var footerTitle: String?
324297

@@ -331,6 +304,7 @@ public class TableViewDataSource<T>: NSObject, UITableViewDataSource {
331304
return footerTitle
332305
}
333306

307+
/// UITableviewDataSource implementation.
334308
public func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
335309
var headerTitle: String?
336310

0 commit comments

Comments
 (0)