Swift version: 5.10
StoreKit products come with price
and priceLocale
properties but it takes a little effort to combine those two together in order to show a user-friendly price in your interface.
Fortunately, one small extension to SKProduct
will provide you with a localizedPrice
property you can use to do that work for you:
extension SKProduct {
var localizedPrice: String {
let formatter = NumberFormatter()
formatter.numberStyle = .currency
formatter.locale = priceLocale
return formatter.string(from: price)!
}
}
SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure and A/B test your entire paywall UI without any code changes or app updates.
Sponsor Hacking with Swift and reach the world's largest Swift community!
Available from iOS 3.0
This is part of the Swift Knowledge Base, a free, searchable collection of solutions for common iOS questions.
Link copied to your pasteboard.