Skip to content

Commit 148e037

Browse files
committed
Add store context extensions for basic product
1 parent cc06f1d commit 148e037

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

Sources/StoreKitPlus/Products/BasicProduct.swift

+20-2
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,16 @@
55
// Created by Daniel Saidi on 2024-12-04.
66
//
77

8-
import SwiftUI
8+
import StoreKit
99

10+
/// This struct is a basic prroduct representation, that you
11+
/// can use to define your products with just an ID and name.
12+
///
13+
/// The ``StoreContext`` is extended with more ways to fetch
14+
/// product information for a basic product.
1015
public struct BasicProduct: Identifiable, ProductRepresentable {
1116

12-
/// Create a new product.
17+
/// Create a basic product representation.
1318
///
1419
/// - Parameters:
1520
/// - id: The App Store string ID of the product.
@@ -26,6 +31,19 @@ public struct BasicProduct: Identifiable, ProductRepresentable {
2631
public let name: String
2732
}
2833

34+
public extension StoreContext {
35+
36+
/// Whether a certain basic product is purchased.
37+
func isProductPurchased(_ prod: BasicProduct) -> Bool {
38+
isProductPurchased(id: prod.id)
39+
}
40+
41+
/// Get a StoreKit product for a certain basic product.
42+
func product(_ prod: BasicProduct) -> Product? {
43+
product(withId: prod.id)
44+
}
45+
}
46+
2947
public extension BasicProduct {
3048

3149
static func preview(_ name: String) -> Self {

0 commit comments

Comments
 (0)