Skip to content

A wrapper around StoreKit 2 APIs that make it easier to create ObservableObjects for in app purchases.

License

Notifications You must be signed in to change notification settings

mostudiosnz/razzil

Repository files navigation

Razzil

A wrapper around the StoreKit 2 APIs used throughout MO Studios iOS projects.

Install

Install using Swift Package Manager.

Usage

All In-App Purchases consist around 2 concepts: Store & Product.

It is suggested to create a singleton Store object and let it conform to the ObservableStore protocol.

Next declare your Products and make references to the products from the store.

// Store.swift

import Razzil
import StoreKit

final class Store: ObservableStore {
  static let shared = Store()
  @Published var state: StoreState = .initial
  
  // Reference the products
  @Published var productOne = ProductOne()
  @Published var productTwo = ProductTwo()
  
  init() {
    // Call StoreKit APIs to load the products and also handle purchase restoration
    ...
  }
}

And to declare the products:

// Products.swift

import Razzil

enum AppProduct: String, Identifiable {
  case productOne
  case productTwo
  var id: String { rawValue }
}

class ProductOne: ObservableObject, ObservableProduct {
  let id: AppProduct
  @Published var state: ProductState
}

class ProductTwo: ObservableObject, ObservableProduct {
  let id: AppProduct
  @Published var state: ProductState
}

Release

Release using git tags. For example:

git tag -a "1.1.0" -m "update observable products to hold ids"
git push origin 1.1.0

About

A wrapper around StoreKit 2 APIs that make it easier to create ObservableObjects for in app purchases.

Topics

Resources

License

Stars

Watchers

Forks

Languages