Skip to content

Commit ff3acb4

Browse files
committed
Updated Getting Started Guide
1 parent 4fe8fbd commit ff3acb4

File tree

66 files changed

+6245
-1103
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+6245
-1103
lines changed

Guides/Getting Started.md

+139-28
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,11 @@
22

33
These instructions will get you a up and running to use `ProgressKit` in your own app.
44

5-
## Prerequisites
6-
7-
Make sure you have the following installed on your system to kick things off:
8-
9-
- [Xcode 10.2+](https://developer.apple.com/xcode/)
10-
- iOS 12+
11-
- [Swift 5+](https://swift.org/getting-started/)
12-
- [Carthage](https://github.com/Carthage/Carthage#installing-carthage)
13-
- [Jazzy](https://github.com/realm/jazzy)
14-
155
## Installation
166

17-
To add `ProgressKit` as Carthage dependency insert the following line to your `Cartfile`:
18-
19-
```
20-
github "Progress4Apple/ProgressKit" ~> 1.0
21-
```
22-
23-
Let `Carthage` download and compile the library by executing the following command:
24-
25-
```
26-
carthage bootstrap --platform iOS
27-
```
7+
See the Getting Started section of the README for how to install `ProgressKit`.
288

29-
As last step add the built libraries in Xcode. See ["Adding frameworks to an application" in the Carthage documentation for further details](https://github.com/Carthage/Carthage#adding-frameworks-to-an-application):
30-
31-
- `ProgressKit.framework`
32-
- `FLAnimatedImage.framework`
33-
- `GiphyCoreSDK.framework`
34-
35-
## Usage
9+
## Configuration
3610

3711
Import `ProgressKit` and call `Progress.configure(...)` in `application(_:didFinishLaunchingWithOptions:)` of your AppDelegate.swift for initialization:
3812

@@ -53,3 +27,140 @@ func application(_ application: UIApplication,
5327
giphyApiKey: "your-giphy-api-key"
5428
)
5529
```
30+
31+
## Create a ViewController
32+
33+
To render the progress bars for the available reports, create a new `UICollectionViewController` in your app and subclass the `ProgressCollectionViewController`:
34+
35+
```
36+
import UIKit
37+
import ProgressKit
38+
39+
class ViewController: ProgressCollectionViewController {
40+
...
41+
}
42+
````
43+
44+
## Set delegate and dataSource
45+
46+
Make sure you set the ViewController's delegate and dataSource objects In your `viewDidLoad`. To begin with, we set both to `self`:
47+
48+
```
49+
import UIKit
50+
import ProgressKit
51+
52+
class ViewController: ProgressCollectionViewController {
53+
54+
override func viewDidLoad() {
55+
super.viewDidLoad()
56+
57+
delegate = self
58+
dataSource = self
59+
}
60+
}
61+
```
62+
63+
Then we make sure our ViewController conforms to `ProgressCollectionViewControllerDelegate`:
64+
65+
```
66+
import UIKit
67+
import ProgressKit
68+
import EventKit
69+
70+
class ViewController: ProgressCollectionViewController, ProgressCollectionViewControllerDelegate {
71+
...
72+
73+
// MARK: ProgressCollectionViewControllerDelegate
74+
75+
func progressCollection(
76+
_ viewController: ProgressCollectionViewController,
77+
handleAuthorizationStatusNotSufficient status: EKAuthorizationStatus
78+
) {
79+
// TODO: Insert your implementation here.
80+
}
81+
82+
83+
func progressCollection(
84+
_ viewController: ProgressCollectionViewController,
85+
didSelectReport report: PKReport
86+
) {
87+
// TODO: Insert your implementation here.
88+
}
89+
90+
91+
func progressCollection(
92+
_ viewController: ProgressCollectionViewController,
93+
handleError error: Error
94+
) {
95+
// TODO: Insert your implementation here.
96+
}
97+
98+
99+
func progressCollection(
100+
_ viewController: ProgressCollectionViewController,
101+
openPreferencesAtURL url: URL,
102+
completionHandler: @escaping ((Bool) -> Void)
103+
) {
104+
UIApplication.shared.open(url, options: [:], completionHandler: completionHandler)
105+
}
106+
}
107+
```
108+
109+
... and finally, our ViewController should also conform to `ProgressCollectionViewControllerDataSource`:
110+
111+
```
112+
import UIKit
113+
import ProgressKit
114+
import EventKit
115+
116+
class ViewController: ProgressCollectionViewController, ProgressCollectionViewControllerDelegate, ProgressCollectionViewControllerDataSource {
117+
...
118+
119+
// MARK: ProgressCollectionViewControllerDataSource
120+
121+
func progressCollection(
122+
_ viewController: ProgressCollectionViewController,
123+
loadReports completionHandler: ([[PKReport]]?, Error?) -> Void
124+
) {
125+
let report = PKReport(
126+
identifier: "1234",
127+
displayStyle: .progress,
128+
listIdentifier: nil,
129+
searchTerm: nil,
130+
isPriorityBased: false,
131+
timeRange: nil,
132+
deadline: nil,
133+
goal: nil,
134+
showInTodayScreen: false,
135+
notificationsEnabled: false
136+
)
137+
let reportSection = [report]
138+
139+
var allReports = [[PKReport]]()
140+
allReports.append(reportSection)
141+
142+
completionHandler(allReports, nil)
143+
}
144+
145+
146+
func progressCollection(
147+
_ viewController: ProgressCollectionViewController,
148+
shouldReload completionHandler: ((Bool) -> Void)
149+
) {
150+
completionHandler(true)
151+
}
152+
153+
154+
func progressCollection(
155+
_ viewController: ProgressCollectionViewController,
156+
saveReports reports: [[PKReport]],
157+
completionHandler: ((Bool, Error?) -> Void)
158+
) {
159+
// TODO: Insert your implementation here.
160+
}
161+
}
162+
```
163+
164+
## Next steps
165+
166+
There you go. That's the bare minimum you need to render reports. As next step you may want to add your implementation for saving and loading reports so the user is able to configure those. For this have a look at `PKReportStore.standard` which makes it easy to persist and query reports to/from disk.

ProgressKit/ProgressCollectionViewController/ProgressCollectionViewController.swift

+7
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,21 @@ import NotificationCenter
3232
*/
3333
open class ProgressCollectionViewController: UICollectionViewController, UICollectionViewDelegateFlowLayout, UICollectionViewDataSourcePrefetching {
3434

35+
/// All currently loaded `PKReport`s provided by the dataSource, grouped by section.
3536
private (set) public var allReports: [[PKReport]] = []
37+
38+
/// The `PKReport` currently selected by the user if any.
3639
private (set) public var selectedReport: PKReport?
3740

41+
/// `ProgressCollectionViewControllerDataSource` for the ViewController.
3842
public var dataSource: ProgressCollectionViewControllerDataSource?
43+
44+
/// `ProgressCollectionViewControllerDelegate` for the ViewController.
3945
public var delegate: ProgressCollectionViewControllerDelegate?
4046

4147
private var notificationToken: PKNotification.Token?
4248

49+
/// Helper function which determines the desired `PKLayoutStyle` based upon a given [`UITraitCollection`](https://developer.apple.com/documentation/uikit/uitraitcollection).
4350
public func layoutStyle(for traitCollection: UITraitCollection) -> PKLayoutStyle {
4451
return traitCollection.horizontalSizeClass == .regular ? .grid : .table
4552
}

0 commit comments

Comments
 (0)