Skip to content

Commit 81cbca4

Browse files
author
Calvin Collins
committed
clean up price string fns
1 parent 8c014b7 commit 81cbca4

1 file changed

Lines changed: 13 additions & 10 deletions

File tree

LUX/Classes/StoreKit/LUXSubscriptionViewController.swift

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,24 +53,27 @@ public func configureSubscriptionCell(product: SKProduct, cell: LUXSubscriptionT
5353
cell?.priceButton.setTitle(productToPriceString(product), for: .normal)
5454
}
5555

56-
public func productToPriceString(_ product: SKProduct) -> String {
57-
let currency = product.priceLocale.currencySymbol ?? ""
58-
let price = product.price
56+
public let productToPriceString: (SKProduct) -> String = fzip(currency, price, productTimeFrame) >>> combinePriceString
57+
58+
public func productTimeFrame(_ product: SKProduct) -> String {
5959
let period = product.subscriptionPeriod?.numberOfUnits
60-
var unit: String?
6160
switch product.subscriptionPeriod?.unit {
6261
case .month:
6362
if (period != nil && period != 1) {
64-
unit = "\(period!) Months"
63+
return "\(period!) Months"
6564
} else {
66-
unit = "Month"
65+
return "Month"
6766
}
6867
case .year:
69-
unit = "Year"
68+
return "Year"
7069
case .none:
71-
unit = ""
70+
return ""
7271
default:
73-
unit = ""
72+
return ""
7473
}
75-
return "\(currency)\(price)/\(unit ?? "")"
7674
}
75+
76+
77+
let currency: (SKProduct) -> String = ^\SKProduct.priceLocale.currencySymbol >>> coalesceNil(with: "")
78+
let price = ^\SKProduct.price
79+
let combinePriceString: ((String, NSDecimalNumber, String)) -> String = { "\($0.0)\($0.1)/\($0.2)" }

0 commit comments

Comments
 (0)