Skip to content

Commit

Permalink
Update price formatting example to use product price locale.
Browse files Browse the repository at this point in the history
  • Loading branch information
bizz84 committed Aug 28, 2016
1 parent 52d657f commit e479b88
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
5 changes: 4 additions & 1 deletion README.md
Expand Up @@ -49,7 +49,10 @@ If there are any pending transactions at this point, these will be reported by t
```swift
SwiftyStoreKit.retrieveProductsInfo(["com.musevisions.SwiftyStoreKit.Purchase1"]) { result in
if let product = result.retrievedProducts.first {
let priceString = NSNumberFormatter.localizedStringFromNumber(product.price ?? 0, numberStyle: .CurrencyStyle)
let numberFormatter = NSNumberFormatter()
numberFormatter.locale = product.priceLocale
numberFormatter.numberStyle = .CurrencyStyle
let priceString = numberFormatter.stringFromNumber(product.price ?? 0) ?? ""
print("Product: \(product.localizedDescription), price: \(priceString)")
}
else if let invalidProductId = result.invalidProductIDs.first {
Expand Down
5 changes: 4 additions & 1 deletion SwiftyStoreDemo/ViewController.swift
Expand Up @@ -179,7 +179,10 @@ extension ViewController {
func alertForProductRetrievalInfo(result: SwiftyStoreKit.RetrieveResults) -> UIAlertController {

if let product = result.retrievedProducts.first {
let priceString = NSNumberFormatter.localizedStringFromNumber(product.price, numberStyle: .CurrencyStyle)
let numberFormatter = NSNumberFormatter()
numberFormatter.locale = product.priceLocale
numberFormatter.numberStyle = .CurrencyStyle
let priceString = numberFormatter.stringFromNumber(product.price ?? 0) ?? ""
return alertWithTitle(product.localizedTitle, message: "\(product.localizedDescription) - \(priceString)")
}
else if let invalidProductId = result.invalidProductIDs.first {
Expand Down
5 changes: 4 additions & 1 deletion SwiftyStoreOSXDemo/ViewController.swift
Expand Up @@ -162,7 +162,10 @@ extension ViewController {
func alertForProductRetrievalInfo(result: SwiftyStoreKit.RetrieveResults) -> NSAlert {

if let product = result.retrievedProducts.first {
let priceString = NSNumberFormatter.localizedStringFromNumber(product.price ?? 0, numberStyle: .CurrencyStyle)
let numberFormatter = NSNumberFormatter()
numberFormatter.locale = product.priceLocale
numberFormatter.numberStyle = .CurrencyStyle
let priceString = numberFormatter.stringFromNumber(product.price ?? 0) ?? ""
return alertWithTitle(product.localizedTitle ?? "no title", message: "\(product.localizedDescription) - \(priceString)")
}
else if let invalidProductId = result.invalidProductIDs.first {
Expand Down

0 comments on commit e479b88

Please sign in to comment.