Skip to content

Commit 5285e58

Browse files
committedDec 4, 2024
Add basic product representation struct
1 parent 6ad6fdb commit 5285e58

File tree

4 files changed

+50
-3
lines changed

4 files changed

+50
-3
lines changed
 

‎RELEASE_NOTES.md

+10
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@ StoreKitPlus will use semver after 1.0.
55
Until then, deprecated features may be removed in any minor version, and breaking changes introduced.
66

77

8+
## 0.4
9+
10+
This version adds more utilities.
11+
12+
### ✨ Features
13+
14+
* `BasicProduct` is a new, lightweight product struct.
15+
16+
17+
818
## 0.4
919

1020
This version makes StoreKitPlus use Swift 6.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//
2+
// BasicProduct.swift
3+
// StoreKitPlus
4+
//
5+
// Created by Daniel Saidi on 2024-12-04.
6+
//
7+
8+
import SwiftUI
9+
10+
public struct BasicProduct: Identifiable, ProductRepresentable {
11+
12+
/// Create a new product.
13+
///
14+
/// - Parameters:
15+
/// - id: The App Store string ID of the product.
16+
/// - name: The product display name.
17+
public init(id: String, name: String) {
18+
self.id = id
19+
self.name = name
20+
}
21+
22+
/// The App Store string ID of the product.
23+
public let id: String
24+
25+
/// The product display name.
26+
public let name: String
27+
}
28+
29+
public extension BasicProduct {
30+
31+
static func preview(_ name: String) -> Self {
32+
.init(
33+
id: "com.danielsaidi.storekitplus.product.preview",
34+
name: name
35+
)
36+
}
37+
}

‎Sources/StoreKitPlus/Products/ProductRepresentable.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import Foundation
1010

1111
/// This protocol can be implemented by types that should be
12-
/// able to represent an app's StoreKit products.
12+
/// able to represent a StoreKit product.
1313
///
1414
/// This protocol can be used to define a local product that
1515
/// uses the same product ID as a real StoreKit product. The
@@ -25,7 +25,7 @@ public protocol ProductRepresentable: Identifiable {
2525
public extension Collection where Element: ProductRepresentable {
2626

2727
/// Get all products available in a ``StoreContext``.
28-
func available(_ context: StoreContext) -> [Self.Element] {
28+
func available(in context: StoreContext) -> [Self.Element] {
2929
let ids = context.productIds
3030
return self.filter { ids.contains($0.id) }
3131
}

‎Sources/StoreKitPlus/StoreKitPlus.docc/StoreKitPlus.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ StoreKitPlus is available under the MIT license.
5959

6060
- ``ProductID``
6161
- ``ProductRepresentable``
62+
- ``BasicProduct``
6263

6364
### Transactions
6465

6566
- ``ValidatableTransaction``
66-

0 commit comments

Comments
 (0)