danthorpe / Money

Swift value types for working with money & currency
MIT License
933 stars 91 forks source link

Able to pass NSLocale to formatter #53

Closed wess closed 8 years ago

wess commented 8 years ago
let money: Money = 99.99
print("She has \(money.formattedWithStyle(.CurrencyPluralStyle, forLocale: .Chinese(.China)))")

Ability to pass NSLocale to the forLocale param

danthorpe commented 8 years ago

Hi @wess - is this not already supported? https://github.com/danthorpe/Money/blob/development/Money/Shared/Money.swift#L112

wess commented 8 years ago

I missed that, but is Locale > NSLocale?

It's how you do it here, I see:


 func formattedWithStyle(style: NSNumberFormatterStyle) -> String {
        return Currency.formattedWithStyle(style, forLocaleId: NSLocale.currentLocale().localeIdentifier)(amount)
    }
danthorpe commented 8 years ago

Sorry - you are quite right. Locale is not NSLocale - this is going to be a problem for Swift 3.

We can add an extension which accepts a NSLocale or identifier? Ultimately it calls though into the static method on Currency.

I can't do this until the weekend - but happy to accept a Pull Request from you if you want to add a method to the same extension in Money.swift?