danthorpe / Money

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

Using a variable for multiple currencies #90

Open tplester opened 6 years ago

tplester commented 6 years ago

I have an app where the user selects one of a set of regions for the app to run in and all the money amounts need to use the currency for that region. I can't work out how to have variables that can be set to any of the strongly typed currency types (e.g. AUD, NZD) since Swift disallows the use of runtime defined Generics types. If I use Money type and force it to a specific currency, its fine until I do any operations that generate a new Money object (such as adding two Money objects), which causes the new Money object to be set to local region instead of the forced region I was using.

I'm using the Swift 4 branch.

Any Ideas on how to do this?