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 Get accurate app localizations in minutes using AI. Choose your languages & receive translations for 40+ markets!
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.