Skip to content

Instantly share code, notes, and snippets.

@natefanaro
Forked from nbasham/StoreKitUtil.swift
Created February 28, 2020 23:47
Show Gist options
  • Save natefanaro/ab835a5c1fc88887f82378e61f2bc66b to your computer and use it in GitHub Desktop.
Save natefanaro/ab835a5c1fc88887f82378e61f2bc66b to your computer and use it in GitHub Desktop.
Enables creation of SKProduct and SKPaymentTransaction so StoreKit work flow and model can be the same on a simulator as it is on a device.
import StoreKit
public extension SKProduct {
convenience init(d : Dictionary<String, AnyObject>) {
self.init()
self.setValue(d["uid"], forKey: "productIdentifier")
self.setValue(d["title"], forKey: "localizedTitle")
self.setValue(d["detail"], forKey: "localizedDescription")
self.setValue(NSDecimalNumber(string: (d["price"] as! String?)), forKey: "price")
self.setValue(NSLocale.currentLocale, forKey: "priceLocale")
}
public override var description: String {
return "productIdentifier \(productIdentifier), localizedTitle \(localizedTitle), localizedDescription \(localizedDescription), price \(price), priceLocale \(priceLocale.identifier)"
}
}
public extension SKPaymentTransaction {
convenience init(uid : String, state : Int) {
self.init()
self.setValue(uid, forKey: "transactionIdentifier")
self.setValue(NSNumber.init(value: Int32(state)), forKey: "transactionState")
self.setValue(NSDate(), forKey: "transactionDate")
}
public override var description: String {
return "transactionIdentifier \(String(describing: transactionIdentifier)), transactionState \(transactionState.rawValue), transactionDate \(transactionDate)"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment