From 148e0377016c64a5d692c774026faff552fa97b1 Mon Sep 17 00:00:00 2001 From: Daniel Saidi Date: Wed, 4 Dec 2024 10:01:24 +0100 Subject: [PATCH] Add store context extensions for basic product --- .../StoreKitPlus/Products/BasicProduct.swift | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/Sources/StoreKitPlus/Products/BasicProduct.swift b/Sources/StoreKitPlus/Products/BasicProduct.swift index 1724b40..1d711db 100644 --- a/Sources/StoreKitPlus/Products/BasicProduct.swift +++ b/Sources/StoreKitPlus/Products/BasicProduct.swift @@ -5,11 +5,16 @@ // Created by Daniel Saidi on 2024-12-04. // -import SwiftUI +import StoreKit +/// This struct is a basic prroduct representation, that you +/// can use to define your products with just an ID and name. +/// +/// The ``StoreContext`` is extended with more ways to fetch +/// product information for a basic product. public struct BasicProduct: Identifiable, ProductRepresentable { - /// Create a new product. + /// Create a basic product representation. /// /// - Parameters: /// - id: The App Store string ID of the product. @@ -26,6 +31,19 @@ public struct BasicProduct: Identifiable, ProductRepresentable { public let name: String } +public extension StoreContext { + + /// Whether a certain basic product is purchased. + func isProductPurchased(_ prod: BasicProduct) -> Bool { + isProductPurchased(id: prod.id) + } + + /// Get a StoreKit product for a certain basic product. + func product(_ prod: BasicProduct) -> Product? { + product(withId: prod.id) + } +} + public extension BasicProduct { static func preview(_ name: String) -> Self {