Skip to content

Commit 9c17c9c

Browse files
committed
Update documentation
1 parent 6ec1034 commit 9c17c9c

File tree

5 files changed

+39
-89
lines changed

5 files changed

+39
-89
lines changed

README.md

+5-11
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<p align="center">
66
<img src="https://img.shields.io/github/v/release/danielsaidi/StoreKitPlus?color=%2300550&sort=semver" alt="Version" />
7-
<img src="https://img.shields.io/badge/Swift-5.6-orange.svg" alt="Swift 5.6" />
7+
<img src="https://img.shields.io/badge/Swift-6.0-orange.svg" alt="Swift 6.0" />
88
<img src="https://img.shields.io/badge/platform-SwiftUI-blue.svg" alt="Swift UI" title="Swift UI" />
99
<img src="https://img.shields.io/github/license/danielsaidi/StoreKitPlus" alt="MIT License" />
1010
<a href="https://twitter.com/danielsaidi">
@@ -18,9 +18,9 @@
1818

1919
## About StoreKitPlus
2020

21-
StoreKitPlus is a Swift SDK that adds extra functionality for working with StoreKit 2, like extensions, observable state, services, etc.
21+
StoreKitPlus is a Swift SDK that makes it easy to integrate with StoreKit 2.
2222

23-
StoreKitPlus has an observable ``StoreContext`` that lets you observe store state, service protocols and classes that let you fetch, purchase and sync products, as well as a ``ProductRepresentable`` protocol that lets you add a local product representation to your app.
23+
StoreKitPlus has an observable ``StoreContext`` that lets you observe store state, services that let you fetch, purchase and sync products, as well as a ``ProductRepresentable`` protocol that lets you use local product representations in your app.
2424

2525

2626

@@ -36,19 +36,13 @@ https://github.com/danielsaidi/StoreKitPlus.git
3636

3737
## Getting started
3838

39-
The [getting started guide][Getting-Started] helps you get started with StoreKitPlus.
39+
See the online [getting started guide][Getting-Started] for information on how to get started.
4040

4141

4242

4343
## Documentation
4444

45-
The [online documentation][Documentation] has more information, articles, code examples, etc.
46-
47-
48-
49-
## Demo Application
50-
51-
This project currently has no demo app, but I will create one if the project gets 100+ stars.
45+
The online [documentation][Documentation] has more information, articles, code examples, etc.
5246

5347

5448

Sources/StoreKitPlus/Services/StandardStoreService.swift

+3-4
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,11 @@ public extension StoreService where Self == StandardStoreService {
3434
/// This class implements the ``StoreService`` protocol, and
3535
/// can be used to integrate with StoreKit.
3636
///
37-
/// This service keeps products and purchases in sync, using
38-
/// the provided ``StoreContext`` and can be used by SwiftUI
39-
/// based apps, to observe context changes.
40-
///
4137
/// You can use this service with a local product collection,
4238
/// by adding a StoreKit configuration file to the app.
39+
///
40+
/// You can use the two ``StoreService/standard(products:)``
41+
/// shorthands to easily create a standard service instance.
4342
open class StandardStoreService: StoreService {
4443

4544
/// Create a service instance for the provided IDs.

Sources/StoreKitPlus/Services/StoreService.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import StoreKit
1515
/// Although some operations can be performed directly using
1616
/// StoreKit like `Product.products(for:)`, the service lets
1717
/// you customize any part of the StoreKit integration.
18-
public protocol StoreService: StoreSyncService {
18+
public protocol StoreService {
1919

2020
/// Get all available products.
2121
func getProducts() async throws -> [Product]

Sources/StoreKitPlus/StoreKitPlus.docc/Getting-Started.md

+26-61
Original file line numberDiff line numberDiff line change
@@ -14,35 +14,21 @@ This article describes how you get started with StoreKitPlus.
1414
}
1515

1616

17-
## Services
18-
1917
StoreKitPlus has services and observable state that help you integrate with StoreKit.
2018

21-
* ``StoreProductService`` can be implemented by types that can fetch StoreKit products.
22-
* ``StorePurchaseService`` can be implemented by types that can purchase StoreKit products.
23-
* ``StoreSyncService`` can be implemented by types that can sync purchases and products.
2419

25-
There is also a ``StoreService`` protocol that implements all these protocols, for when you want a single service to do everything.
2620

27-
``StandardStoreProductService``, ``StandardStorePurchaseService`` and ``StandardStoreService`` implement these protocols and can be subclassed to customize their behavior.
21+
## Services
2822

23+
A ``StoreService`` can be used to integrate with StoreKit, such as fetching and purchasing products, restoring purchases, etc.
2924

25+
You can use the ``StandardStoreService`` as is, or subclass it to make modifications to any part of the StoreKit integration.
3026

31-
## Observable state
3227

33-
StoreKitPlus has an observable ``StoreContext`` that keeps track of the available and purchased products for an app. It can be injected into the store services to automatically be kept in sync.
3428

35-
For instance, injecting a context into a ``StandardStoreService`` and calling ``StoreSyncService/syncStoreData()`` will automatically write products and transactions to the context:
29+
## Observable state
3630

37-
```swift
38-
let productIds = ["com.your-app.productid"]
39-
let context = StoreContext()
40-
let service = StandardStoreService(
41-
productIds: productIds,
42-
context: context
43-
)
44-
try await service.syncStoreData()
45-
```
31+
StoreKitPlus has an observable ``StoreContext`` that keeps track of the available and purchased products for an app. It can be injected into the store service's functions to automatically keep it in sync.
4632

4733
Although StoreKit products and transactions are not codable, this context will persist products and purchases by their ID, which means that you can use local product representations to keep track of products and purchases in your app.
4834

@@ -87,7 +73,6 @@ Since some operations require real StoreKit `Product` values, you should display
8773

8874

8975

90-
9176
## Fetching products
9277

9378
You can use the native `Product` type to fetch products with StoreKit:
@@ -97,18 +82,15 @@ let productIds = ["com.your-app.productid"]
9782
let products = try await Product.products(for: productIds)
9883
```
9984

100-
You can also use a ``StoreProductService``, for instance this standard one:
85+
You can also use a ``StoreService``, for instance this standard one:
10186

10287
```swift
103-
let productIds = ["com.your-app.productid"]
104-
let context = StoreContext()
105-
let service = StandardStoreProductService(
106-
productIds: productIds,
107-
context: context)
88+
let ids = ["com.your-app.productid"]
89+
let service = StandardStoreService(productIds: ids)
10890
let products = try await service.getProducts()
10991
```
11092

111-
The standard service communicates with StoreKit and syncs the result with the provided context.
93+
You can subclass ``StandardStoreService`` to customize the fetch operation.
11294

11395

11496

@@ -127,32 +109,27 @@ switch result {
127109
return result
128110
```
129111

130-
However, purchases involve a bunch of steps and can become pretty complicated. To make things easier, you can also use a ``StorePurchaseService``, for instance this standard one:
112+
Since purchases involve a bunch of steps and can become complicated, you can also use a ``StoreService``:
131113

132114
```swift
133-
let productIds = ["com.your-app.productid"]
134-
let context = StoreContext()
135-
let service = StandardStorePurchaseService(productIds: productIds, context: context)
115+
let ids = ["com.your-app.productid"]
116+
let service = StandardStorePurchaseService(productIds: ids)
136117
let result = try await service.purchase(product)
137118
```
138119

139-
The standard service communicates with StoreKit and syncs the result with the provided context.
120+
The ``StandardStoreService`` will automatically verify and finish the purchase transactions.
140121

141122

142123

143124
## Restoring purchases
144125

145126
You can use the native `StoreKit.Product` to verify transactions and see which that are purchased, not expired, not revoked etc.
146127

147-
However, this involves many steps and can become pretty complicated. To make things easier, you can also use a ``StorePurchaseService``, for instance this standard one:
128+
However, this involves many steps and can become complicated. To make things easier, you can also use a ``StoreService``:
148129

149130
```swift
150-
let productIds = ["com.your-app.productid"]
151-
let context = StoreContext()
152-
let service = StandardStorePurchaseService(
153-
productIds: productIds,
154-
context: context
155-
)
131+
let ids = ["com.your-app.productid"]
132+
let service = StandardStorePurchaseService(productIds: ids)
156133
try await service.restorePurchases()
157134
```
158135

@@ -164,16 +141,13 @@ The standard service communicates with StoreKit and syncs the result with the pr
164141

165142
To perform a product and purchase sync, you can fetch products and transactions from StoreKit.
166143

167-
However, this involves a bunch of steps and can become pretty complicated. To make things easier, you can also use a ``StoreSyncService``, for instance this standard one:
144+
Using a ``StoreService`` lets you easily sync all data to a ``StoreContext``:
168145

169146
```swift
170-
let productIds = ["com.your-app.productid"]
147+
let ids = ["com.your-app.productid"]
171148
let context = StoreContext()
172-
let service = StandardStoreService(
173-
productIds: productIds,
174-
context: context
175-
)
176-
try await service.syncStoreData()
149+
let service = StandardStoreService(productIds: ids)
150+
try await service.syncStoreData(to: context)
177151
```
178152

179153
The standard service communicates with StoreKit and syncs the result with the provided context.
@@ -189,7 +163,7 @@ To sync data when your app launches or becomes active, you can listen to its sce
189163
struct MyApp: App {
190164

191165
@StateObject
192-
private var storeContext = StoreContext()
166+
private var context = StoreContext()
193167

194168
@Environment(\.scenePhase)
195169
private var scenePhase
@@ -198,33 +172,24 @@ struct MyApp: App {
198172
WindowGroup {
199173
RootView()
200174
.onChange(of: scenePhase, perform: syncStoreData)
201-
.environmentObject(storeContext)
202175
}
203176
}
204177
}
205178

206179
private extension MyApp {
207180

208-
// I use a service provider to resolve services, but you
209-
// can create a service directly, like this:
210-
var storeService: StoreService {
211-
let productIds = ["com.your-app.productid"]
212-
let service = StandardStoreService(
213-
productIds: productIds,
214-
context: storeContext
215-
)
216-
}
217-
218181
func syncStoreData(for phase: ScenePhase) {
219-
guard phase == .active else { return
182+
guard phase == .active else { return }
183+
let ids = ["com.your-app.productid"]
184+
let service = StandardStoreService(productIds: ids)
220185
Task {
221-
try await storeService.syncStoreData()
186+
try await storeService.syncStoreData(to: context)
222187
}
223188
}
224189
}
225190
```
226191

227-
Since the standard implementations automatically sync changes to the provided context, injecting the context as an environment object will make the global state available to the entire app.
192+
You can inject the context as an `EnvironmentObject` to make the global state available to the entire app.
228193

229194

230195

Sources/StoreKitPlus/StoreKitPlus.docc/StoreKitPlus.md

+4-12
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ StoreKitPlus is a Swift SDK that adds extra functionality for working with Store
88

99
![StoreKitPlus logo](Logo.png)
1010

11-
StoreKitPlus is a Swift SDK that adds extra functionality for working with StoreKit 2, like extensions, observable state, services, etc.
11+
StoreKitPlus is a Swift SDK that makes it easy to integrate with StoreKit 2.
1212

13-
StoreKitPlus has an observable ``StoreContext`` that lets you observe state, service protocols and classes that let you fetch, purchase and sync products, as well as a ``ProductRepresentable`` protocol that lets you add a local product representation to your app.
13+
StoreKitPlus has an observable ``StoreContext`` that lets you observe store state, services that let you fetch, purchase and sync products, as well as a ``ProductRepresentable`` protocol that lets you use local product representations in your app.
1414

1515

1616

@@ -53,22 +53,14 @@ StoreKitPlus is available under the MIT license.
5353
- ``StoreContext``
5454
- ``StoreService``
5555
- ``StandardStoreService``
56+
- ``StoreServiceError``
5657

5758
### Products
5859

5960
- ``ProductID``
6061
- ``ProductRepresentable``
6162

62-
### Services
63-
64-
- ``StandardStoreProductService``
65-
- ``StandardStorePurchaseService``
66-
- ``StoreProductService``
67-
- ``StorePurchaseService``
68-
- ``StoreSyncService``
69-
- ``StoreServiceError``
70-
71-
### Validation
63+
### Transactions
7264

7365
- ``ValidatableTransaction``
7466

0 commit comments

Comments
 (0)