Structures
The following structures are available globally.
-
A structure representing the basic attributes of a currency.
Represents the English name, ISO 4217 code, and minor unit of a currency.
Most users wont need to construct their own instance of a currency, but instead access one using either:
Currencies.allCurrencies.with(currencyCode:)Currencies.GBP,Currencies.USD, etc.See moreSee also
Declaration
Swift
public struct Currency : Equatable, Hashable
-
A Swift representation of money / monetary amounts and ISO 4217 currency designations. Supports manipulation and combination of monetary amounts of a single currency or multiple currencies.
Handles minor units (the exponent, e.g. cents for USD) for each currency as specified in the ISO 4217 standard. Simple manipulation includes consolidating / combining amounts.
MonetaryAmountvalues that have the sameCurrencywill be added together,MonetaryAmountvalues with uniqueCurrencyvalues will be added to the result on their own.Usage Example
let moneyA = 12.00.in(.USD) let moneyB = 18.00.in(.USD) let moneyC = 6.00.in(.GBP) // result would equal [30.00.in(.USD), 6.00.in(.GBP)] let result = [moneyA, moneyB, moneyC].consolidating(moneyB)The underlying value for the amount is represented by a
DynamicRoundedDecimalwhich itself uses the SwiftDecimaltype.DynamicRoundedDecimalhandles rounding internally as declared by the given currency’sminorUnit.Usage Example
// moneyA and moneyB are equal and represent US$28.53 let moneyA = MonetaryAmount(currency: Currency.USD, value: Decimal(string: "28.529372")!) let moneyB = 28.53.in(.USD)Note
MonetaryAmountdoes not do any FX or conversion of currencies, it keeps each individual currency subtotal separate.See moreSee also
Declaration
Swift
public struct MonetaryAmount : Equatable, Hashable, CustomStringConvertible
View on GitHub
Structures Reference