Skip to content

Instantly share code, notes, and snippets.

@nbasham
Created June 22, 2016 21:10
Show Gist options
  • Save nbasham/5724ebb048940d66a050ab5b39eb463a to your computer and use it in GitHub Desktop.
Save nbasham/5724ebb048940d66a050ab5b39eb463a 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.localeIdentifier)"
}
}
public extension SKPaymentTransaction {
convenience init(uid : String, state : Int) {
self.init()
self.setValue(uid, forKey: "transactionIdentifier")
self.setValue(NSNumber.init(int: Int32(state)), forKey: "transactionState")
self.setValue(NSDate(), forKey: "transactionDate")
}
public override var description: String {
return "transactionIdentifier \(transactionIdentifier), transactionState \(transactionState.rawValue), transactionDate \(transactionDate)"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment