Skip to content

Commit

Permalink
Merge pull request #318 from bizz84/feature/localized-introductory-price
Browse files Browse the repository at this point in the history
Add localizedIntroductoryPrice helper
  • Loading branch information
bizz84 authored Dec 16, 2017
2 parents d585a54 + 21d8f9c commit 3e17574
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

All notable changes to this project will be documented in this file.

## [0.11.1](https://github.com/bizz84/SwiftyStoreKit/releases/tag/0.11.1) Add `transactionDate` to `PaymentTransaction`
## [0.11.1](https://github.com/bizz84/SwiftyStoreKit/releases/tag/0.11.1) Add `PaymentTransaction.transactionDate` and `SKProduct.localizedIntroductoryPrice`

* Add `transactionDate` to `PaymentTransaction` ([#316](https://github.com/bizz84/SwiftyStoreKit/pull/316), see [#312](https://github.com/bizz84/SwiftyStoreKit/issues/312)).
* Add `localizedIntroductoryPrice` to `SKProduct` ([#318](https://github.com/bizz84/SwiftyStoreKit/pull/318)).

## [0.11.0](https://github.com/bizz84/SwiftyStoreKit/releases/tag/0.11.0) Add `fetchReceipt` method + update `verifyReceipt` and `ReceiptValidator` protocol

Expand Down
16 changes: 14 additions & 2 deletions SwiftyStoreKit/SKProduct+LocalizedPrice.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,21 @@ import StoreKit
public extension SKProduct {

public var localizedPrice: String? {
return formattedPrice(price: price, locale: priceLocale)
}

@available(iOS 11.2, OSX 10.13.2, tvOS 11.2, *)
public var localizedIntroductoryPrice: String? {
guard let introductoryPrice = introductoryPrice else {
return nil
}
return formattedPrice(price: introductoryPrice.price, locale: introductoryPrice.priceLocale)
}

private func formattedPrice(price: NSDecimalNumber, locale: Locale) -> String? {
let numberFormatter = NumberFormatter()
numberFormatter.locale = self.priceLocale
numberFormatter.locale = locale
numberFormatter.numberStyle = .currency
return numberFormatter.string(from: self.price)
return numberFormatter.string(from: price)
}
}

0 comments on commit 3e17574

Please sign in to comment.