NEW: Master Swift design patterns with my latest book! >>

How to show the price of an SKProduct

Written by Paul Hudson    @twostraws

StoreKit products come with price and priceLocale property, 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)!
    }
}

Available from iOS 3.0

Did this solution work for you? Please pass it on!

Other people are reading…

About the Swift Knowledge Base

This is part of the Swift Knowledge Base, a free, searchable collection of solutions for common iOS questions.

Want to build macOS apps?

Hacking with macOS delivers 18 awesome projects that teach you macOS development in no time – take control of your desktop today!

Click here to visit the Hacking with Swift store >>