Skip to content

Commit 3e17574

Browse files
authored
Merge pull request #318 from bizz84/feature/localized-introductory-price
Add localizedIntroductoryPrice helper
2 parents d585a54 + 21d8f9c commit 3e17574

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

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

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

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

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

SwiftyStoreKit/SKProduct+LocalizedPrice.swift

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,21 @@ import StoreKit
2828
public extension SKProduct {
2929

3030
public var localizedPrice: String? {
31+
return formattedPrice(price: price, locale: priceLocale)
32+
}
33+
34+
@available(iOS 11.2, OSX 10.13.2, tvOS 11.2, *)
35+
public var localizedIntroductoryPrice: String? {
36+
guard let introductoryPrice = introductoryPrice else {
37+
return nil
38+
}
39+
return formattedPrice(price: introductoryPrice.price, locale: introductoryPrice.priceLocale)
40+
}
41+
42+
private func formattedPrice(price: NSDecimalNumber, locale: Locale) -> String? {
3143
let numberFormatter = NumberFormatter()
32-
numberFormatter.locale = self.priceLocale
44+
numberFormatter.locale = locale
3345
numberFormatter.numberStyle = .currency
34-
return numberFormatter.string(from: self.price)
46+
return numberFormatter.string(from: price)
3547
}
3648
}

0 commit comments

Comments
 (0)