/CurrencyConverter

A simple currency converter written in Swift 5 that gets the exchange rates from the European Central Bank.

Primary LanguageSwiftMIT LicenseMIT

CurrencyConverter (Swift 5.0)

A simple currency converter written in Swift 5.
The exchange rates are fetched from the following XML file: https://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml
This Currency Converter is used in the Objective Calculator app. Check it out: http://itunes.apple.com/app/id1287000522

How to use:
• Add the "CurrencyConverter.swift" file to your project
• Create a CurrencyConverter instance
• Call the updateExchangeRates method
• After it updates the exchange rates, call the convert method
• That's it!

Example

class ViewController: UIViewController {

    // Creates the Currency Converter instance:
    let currencyConverter = CurrencyConverter()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        // Updates the exchange rates:
        currencyConverter.updateExchangeRates(completion: {
            // The code inside here runs after all the data is fetched.
            
            // Now you can convert any currency:
            // • Example_1 (USD to EUR):
            let doubleResult = self.currencyConverter.convert(10, valueCurrency: .USD, outputCurrency: .EUR)
            print("••• 10 USD = \(doubleResult!) EUR •••")
            
            // • Example_2 (EUR to GBP) - Returning a formatted String:
            let formattedResult = self.currencyConverter.convertAndFormat(10, valueCurrency: .EUR, outputCurrency: .GBP, numberStyle: .decimal, decimalPlaces: 4)
            print("••• Formatted Result (10 EUR to GBP): \(formattedResult!) •••")
        })
    }

}

List of currently supported currencies:

USD US dollar
JPY Japanese yen
BGN Bulgarian lev
CZK Czech koruna
DKK Danish krone
GBP Pound sterling
HUF Hungarian forint
PLN Polish zloty
RON Romanian leu
SEK Swedish krona
CHF Swiss franc
ISK Icelandic krona
NOK Norwegian krone
HRK Croatian kuna
RUB Russian rouble
TRY Turkish lira
AUD Australian dollar
BRL Brazilian real
CAD Canadian dollar
CNY Chinese yuan renminbi
HKD Hong Kong dollar
IDR Indonesian rupiah
ILS Israeli shekel
INR Indian rupee
KRW South Korean won
MXN Mexican peso
MYR Malaysian ringgit
NZD New Zealand dollar
PHP Philippine peso
SGD Singapore dollar
THB Thai baht
ZAR South African rand

License

InfiniteScrollingBackground project is licensed under MIT License (MIT-License or https://opensource.org/licenses/MIT)