Skip to content

Interact with and calculate values of currencies in a type-safe way.

License

Notifications You must be signed in to change notification settings

peek-travel/swift-currency

Repository files navigation

Swift Currency

MIT License Documentation Badge

Swift Compatability Platform Compatability

Package Tests codecov

Maintainability

Introduction

Swift Currency provides an ISO 4217 framework for representing currencies in a type-safe way in Swift.

It provides many conveniences for working with currencies, such as literal representations, value formatting, and mathematics.

import Currency
import Foundation

let dollars = USD(30.01)
print(dollars)
// 30.01 USD
print(dollars * 2)
// 60.02 USD
print(dollars.distributedEvenly(intoParts: 6))
// [USD(1.68), USD(1.68), USD(1.68), USD(1.67), USD(1.67), USD(1.67)]

let pounds = GBP(109.23)
print(dollars + pounds)
// compile error

let jpy: JPY = 399
print("The total price is \(jpy.localizedString()).")
// "The total price is ¥399.", assuming `Foundation.Locale.current` is "en_US"

let euro = EUR(29.09)
print("Der Gesamtpreis beträgt \(localize: euro, for: .init(identifier: "de_DE")).")
// "Der Gesamtpreis beträgt 29,09 €."

For more detailed examples, see the documentation.

Language and Platform Support

This library makes a best effort to run tests everywhere it is officially possible to use this library, as defined as official language support.

However, the macOS cloud runners for GitHub Actions makes it a bit difficult to test the entire range of possibilities as they deprecate macOS versions or don't provide installs of newer Xcode versions.

To verify if the package works as expected for your desired platform, review the latest test results.

Installing

Add the package reference to your Package.swift to install via SwiftPM.

dependencies: [
    .package(url: "https://github.com/peek-travel/swift-currency", from: "0.6.0")
]

Documentation

Documentation is available from the Swift Package Index.

Questions

For bugs or feature requests, file a new issue.

Changelog

SemVer changes are documented for each release on the releases page.

Contributing

Check out CONTRIBUTING.md for more information on how to help with SwiftCurrency.

Contributors

Check out CONTRIBUTORS.txt to see the full list. This list is updated for each release.

License

MIT

Copyright (c) 2020-present, Peek Travel Inc.

This project contains code written by others not affliated with this project. All copyright claims are reserved by them. For a full list, with their claimed rights, see NOTICE.txt

Swift is a registered trademark of Apple, Inc. Any use of their trademark does not imply any affiliation with or endorsement by them, and all rights are reserved by them.