Skip to content

Commit

Permalink
Add store context extensions for basic product
Browse files Browse the repository at this point in the history
  • Loading branch information
danielsaidi committed Dec 4, 2024
1 parent cc06f1d commit 148e037
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions Sources/StoreKitPlus/Products/BasicProduct.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 {
Expand Down

0 comments on commit 148e037

Please sign in to comment.