Giter VIP home page Giter VIP logo

currencyconverter's Introduction

CurrencyConverter

Build Status

Utilities for doing currency conversion with the Money library.

This functionality is discussed in Chapter 3 of Flight School Guide to Swift Numbers.

Requirements

  • Swift 4.0+

Installation

Swift Package Manager

Add the CurrencyConverter package to your target dependencies in Package.swift:

import PackageDescription

let package = Package(
  name: "YourProject",
  dependencies: [
    .package(
        url: "https://github.com/Flight-School/CurrencyConverter",
        from: "1.0.0"
    ),
  ]
)

Then run the swift build command to build your project.

Carthage

To use CurrencyConverter in your Xcode project using Carthage, specify it in Cartfile:

github "Flight-School/CurrencyConverter" ~> 1.0.0

Then run the carthage update command to build the framework, and drag the built CurrencyConverter.framework into your Xcode project.

Usage

A currency pair describes the relative value of one currency in terms of another. You can create a CurrencyPair object with a specified exchange rate to convert from a monetary amount in one currency to the other:

let EURtoUSD = CurrencyPair<EUR, USD>(rate: 1.17) // as of June 1st, 2018

let euros: Money<EUR> = 123.45
let dollars = EURtoUSD.convert(euros).rounded // "$144.44"

Note: This library doesn't include functionality for querying the current exchange rates of currencies. You can get this information from various third party web applications.

To only allow conversion in one direction, create a type that conforms to the UnidirectionalCurrencyConverter protocol. If you want to offer different rates depending on the direction of conversion (that is, a rate going from variable to fixed that isn't the inverse of going the other way) create a type that conforms to the BidirectionalCurrencyConverter protocol.

License

MIT

Contact

Mattt (@mattt)

currencyconverter's People

Contributors

mattt avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.