Skip to content
This repository has been archived by the owner on Jul 2, 2018. It is now read-only.

Commit

Permalink
Merge branch 'release/1.6.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
danthorpe committed Feb 28, 2016
2 parents 595600e + 4ce267d commit 621d6be
Show file tree
Hide file tree
Showing 11 changed files with 103 additions and 82 deletions.
2 changes: 1 addition & 1 deletion .jazzy.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
author_name: Daniel Thorpe
author_url: http://danthorpe.me
module_name: Money
module_version: 1.5.1
module_version: 1.6.0
github_url: https://github.com/danthorpe/Money
readme: README.md
podspec: Money.podspec
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 1.6.0
1. [[MNY-39](https://github.com/danthorpe/Money/pull/39)]: Updates the spelling of CocoaPods, thanks [https://github.com/ReadmeCritic](@ReadmeCritic)!
2. [[MNY-34](https://github.com/danthorpe/Money/pull/34)]: Refactors `CurrencyType` to remove the formatter property, and include a default `CurrencyStyle`. This update makes it a lot easier to make custom currency types, and overall improves or fixes bugs with the ISO currency types. If you have custom currencies you may need to perform some slight refactoring, but it shouldn’t be too complex.

# 1.5.1
Cleans up a few issues related to updating to the latest Carthage, and the example project.

Expand Down
4 changes: 2 additions & 2 deletions Money.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "Money"
s.version = "1.5.1"
s.version = "1.6.0"
s.summary = "Swift types for working with Money."
s.description = <<-DESC
Expand All @@ -15,7 +15,7 @@ Pod::Spec.new do |s|
s.author = { "Daniel Thorpe" => "@danthorpe" }
s.source = { :git => "https://github.com/danthorpe/Money.git", :tag => s.version.to_s }
s.module_name = 'Money'
s.documentation_url = 'http://docs.danthorpe.me/money/1.5.1/index.html'
s.documentation_url = 'http://docs.danthorpe.me/money/1.6.0/index.html'
s.social_media_url = 'https://twitter.com/danthorpe'
s.requires_arc = true
s.ios.deployment_target = '8.0'
Expand Down
34 changes: 15 additions & 19 deletions Money.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@
6557F4C91BEB7F3D003CD2BF /* ValueCoding.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6557F4C81BEB7F3D003CD2BF /* ValueCoding.framework */; };
6557F4CB1BEB7F46003CD2BF /* ValueCoding.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6557F4CA1BEB7F46003CD2BF /* ValueCoding.framework */; };
6557F4CD1BEB7F51003CD2BF /* ValueCoding.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6557F4CC1BEB7F51003CD2BF /* ValueCoding.framework */; };
65882AFB1C6CB02C0056E00B /* Bitcoin.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65882AFA1C6CAF9A0056E00B /* Bitcoin.swift */; };
65882AFC1C6CB02D0056E00B /* Bitcoin.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65882AFA1C6CAF9A0056E00B /* Bitcoin.swift */; };
65882AFD1C6CB02D0056E00B /* Bitcoin.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65882AFA1C6CAF9A0056E00B /* Bitcoin.swift */; };
65882AFE1C6CB02E0056E00B /* Bitcoin.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65882AFA1C6CAF9A0056E00B /* Bitcoin.swift */; };
65B92ADE1BE0E4A700F82024 /* Money.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 65B92AD31BE0E4A700F82024 /* Money.framework */; };
65B92B071BE0E4D800F82024 /* Money.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 65B92AFD1BE0E4D800F82024 /* Money.framework */; };
65B92B231BE0E4E700F82024 /* Money.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 65B92B191BE0E4E700F82024 /* Money.framework */; };
Expand Down Expand Up @@ -86,10 +90,6 @@
65DEE34E1BFA0F370043A718 /* NSDecimalNumberExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65DEE32D1BFA0F370043A718 /* NSDecimalNumberExtensions.swift */; };
65DEE34F1BFA0F370043A718 /* NSDecimalNumberExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65DEE32D1BFA0F370043A718 /* NSDecimalNumberExtensions.swift */; };
65DEE3501BFA0F370043A718 /* NSDecimalNumberExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65DEE32D1BFA0F370043A718 /* NSDecimalNumberExtensions.swift */; };
65DEE3511BFA0F370043A718 /* Bitcoin.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65DEE32F1BFA0F370043A718 /* Bitcoin.swift */; };
65DEE3521BFA0F370043A718 /* Bitcoin.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65DEE32F1BFA0F370043A718 /* Bitcoin.swift */; };
65DEE3531BFA0F370043A718 /* Bitcoin.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65DEE32F1BFA0F370043A718 /* Bitcoin.swift */; };
65DEE3541BFA0F370043A718 /* Bitcoin.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65DEE32F1BFA0F370043A718 /* Bitcoin.swift */; };
65DEE3611BFA0F370043A718 /* Money.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65DEE3331BFA0F370043A718 /* Money.swift */; };
65DEE3621BFA0F370043A718 /* Money.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65DEE3331BFA0F370043A718 /* Money.swift */; };
65DEE3631BFA0F370043A718 /* Money.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65DEE3331BFA0F370043A718 /* Money.swift */; };
Expand Down Expand Up @@ -161,6 +161,7 @@
6557F4C81BEB7F3D003CD2BF /* ValueCoding.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ValueCoding.framework; path = Carthage/Build/watchOS/ValueCoding.framework; sourceTree = "<group>"; };
6557F4CA1BEB7F46003CD2BF /* ValueCoding.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ValueCoding.framework; path = Carthage/Build/tvOS/ValueCoding.framework; sourceTree = "<group>"; };
6557F4CC1BEB7F51003CD2BF /* ValueCoding.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ValueCoding.framework; path = Carthage/Build/Mac/ValueCoding.framework; sourceTree = "<group>"; };
65882AFA1C6CAF9A0056E00B /* Bitcoin.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Bitcoin.swift; sourceTree = "<group>"; };
65A876D61BE6491800E26F22 /* Generate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = Generate.swift; path = "Supporting Files/Generate.swift"; sourceTree = SOURCE_ROOT; };
65B92AD31BE0E4A700F82024 /* Money.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Money.framework; sourceTree = BUILT_PRODUCTS_DIR; };
65B92ADD1BE0E4A700F82024 /* Money-iOSTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "Money-iOSTests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
Expand All @@ -186,7 +187,6 @@
65DEE32B1BFA0F370043A718 /* DecimalNumberType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DecimalNumberType.swift; sourceTree = "<group>"; };
65DEE32C1BFA0F370043A718 /* NSDecimalExtensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NSDecimalExtensions.swift; sourceTree = "<group>"; };
65DEE32D1BFA0F370043A718 /* NSDecimalNumberExtensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NSDecimalNumberExtensions.swift; sourceTree = "<group>"; };
65DEE32F1BFA0F370043A718 /* Bitcoin.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Bitcoin.swift; sourceTree = "<group>"; };
65DEE3331BFA0F370043A718 /* Money.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Money.swift; sourceTree = "<group>"; };
65DEE3341BFA0F370043A718 /* Support.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Support.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
Expand Down Expand Up @@ -353,12 +353,12 @@
isa = PBXGroup;
children = (
65DEE3271BFA0F370043A718 /* Autogenerated.swift */,
65882AFA1C6CAF9A0056E00B /* Bitcoin.swift */,
65DEE3281BFA0F370043A718 /* Currency.swift */,
65579FB51C0228EB00C3F8C7 /* Locale.swift */,
65DEE3331BFA0F370043A718 /* Money.swift */,
65DEE3341BFA0F370043A718 /* Support.swift */,
65DEE3291BFA0F370043A718 /* Decimal */,
65DEE32E1BFA0F370043A718 /* FX */,
);
path = Shared;
sourceTree = "<group>";
Expand All @@ -374,14 +374,6 @@
path = Decimal;
sourceTree = "<group>";
};
65DEE32E1BFA0F370043A718 /* FX */ = {
isa = PBXGroup;
children = (
65DEE32F1BFA0F370043A718 /* Bitcoin.swift */,
);
path = FX;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXHeadersBuildPhase section */
Expand Down Expand Up @@ -559,7 +551,7 @@
65B92AC81BE0E46C00F82024 /* Project object */ = {
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0710;
LastSwiftUpdateCheck = 0720;
LastUpgradeCheck = 0720;
TargetAttributes = {
65A876D81BE65FAF00E26F22 = {
Expand Down Expand Up @@ -741,9 +733,9 @@
65DEE34D1BFA0F370043A718 /* NSDecimalNumberExtensions.swift in Sources */,
65DEE3411BFA0F370043A718 /* Decimal.swift in Sources */,
65DEE33D1BFA0F370043A718 /* Currency.swift in Sources */,
65882AFB1C6CB02C0056E00B /* Bitcoin.swift in Sources */,
65DEE3611BFA0F370043A718 /* Money.swift in Sources */,
65DEE3391BFA0F370043A718 /* Autogenerated.swift in Sources */,
65DEE3511BFA0F370043A718 /* Bitcoin.swift in Sources */,
65DEE3351BFA0F370043A718 /* ApplePay.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -774,10 +766,10 @@
65DEE34E1BFA0F370043A718 /* NSDecimalNumberExtensions.swift in Sources */,
65DEE3421BFA0F370043A718 /* Decimal.swift in Sources */,
65DEE33E1BFA0F370043A718 /* Currency.swift in Sources */,
65882AFC1C6CB02D0056E00B /* Bitcoin.swift in Sources */,
65DEE3621BFA0F370043A718 /* Money.swift in Sources */,
65579FB71C0228EB00C3F8C7 /* Locale.swift in Sources */,
65DEE33A1BFA0F370043A718 /* Autogenerated.swift in Sources */,
65DEE3521BFA0F370043A718 /* Bitcoin.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -791,10 +783,10 @@
65DEE34F1BFA0F370043A718 /* NSDecimalNumberExtensions.swift in Sources */,
65DEE3431BFA0F370043A718 /* Decimal.swift in Sources */,
65DEE33F1BFA0F370043A718 /* Currency.swift in Sources */,
65882AFD1C6CB02D0056E00B /* Bitcoin.swift in Sources */,
65DEE3631BFA0F370043A718 /* Money.swift in Sources */,
65579FB81C0228EB00C3F8C7 /* Locale.swift in Sources */,
65DEE33B1BFA0F370043A718 /* Autogenerated.swift in Sources */,
65DEE3531BFA0F370043A718 /* Bitcoin.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -823,10 +815,10 @@
65DEE3501BFA0F370043A718 /* NSDecimalNumberExtensions.swift in Sources */,
65DEE3441BFA0F370043A718 /* Decimal.swift in Sources */,
65DEE3401BFA0F370043A718 /* Currency.swift in Sources */,
65882AFE1C6CB02E0056E00B /* Bitcoin.swift in Sources */,
65DEE3641BFA0F370043A718 /* Money.swift in Sources */,
65579FB91C0228EB00C3F8C7 /* Locale.swift in Sources */,
65DEE33C1BFA0F370043A718 /* Autogenerated.swift in Sources */,
65DEE3541BFA0F370043A718 /* Bitcoin.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -889,13 +881,17 @@
65A876DA1BE65FAF00E26F22 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Debug;
};
65A876DB1BE65FAF00E26F22 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Release;
Expand Down
36 changes: 23 additions & 13 deletions Money/Shared/FX/Bitcoin.swift → Money/Shared/Bitcoin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,20 @@ import Foundation
*/
public protocol BitcoinCurrencyType: CryptoCurrencyType { }

public extension BitcoinCurrencyType {

/// The smallest unit of Bitcoin is the Satoshi
/// - see: https://en.bitcoin.it/wiki/Satoshi_(unit)
static var scale: Int {
return 8
}

/// - returns: the currency symbol
static var symbol: String? {
return "Ƀ"
}
}

public extension Currency {

/**
Expand All @@ -55,18 +69,14 @@ public extension Currency {
/// - returns: the proposed ISO 4217 currency code
public static let code = "XBT"

/// The smallest unit of Bitcoin is the Satoshi
/// - see: https://en.bitcoin.it/wiki/Satoshi_(unit)
public static let scale: Int = 8

/// - returns: a configured NSNumberFormatter
public static let formatter: NSNumberFormatter = {
let fmtr = NSNumberFormatter()
fmtr.numberStyle = .CurrencyStyle
fmtr.maximumFractionDigits = scale
fmtr.currencySymbol = "Ƀ"
return fmtr
}()
// public static let formatter: NSNumberFormatter = {
// let fmtr = NSNumberFormatter()
// fmtr.numberStyle = .CurrencyStyle
// fmtr.maximumFractionDigits = scale
// fmtr.currencySymbol = "Ƀ"
// return fmtr
// }()
}

/**
Expand All @@ -76,8 +86,8 @@ public extension Currency {
*/
struct BTC: BitcoinCurrencyType {
public static let code = "BTC"
public static let scale = Currency.XBT.scale
public static let formatter = Currency.XBT.formatter
// public static let scale = Currency.XBT.scale
// public static let formatter = Currency.XBT.formatter
}
}

Expand Down
89 changes: 51 additions & 38 deletions Money/Shared/Currency.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,20 @@ public protocol CurrencyType: DecimalNumberBehaviorType {
/// The currency symbol
static var symbol: String? { get }

/// A number formatter for the currency
static var formatter: NSNumberFormatter { get }

/// Default formatting style
static var defaultFormattingStyle: NSNumberFormatterStyle { get }
static func formattedWithStyle(style: NSNumberFormatterStyle, forLocaleId localeId: String) -> NSDecimalNumber -> String

static func formattedWithStyle(style: NSNumberFormatterStyle, forLocale locale: Locale) -> NSDecimalNumber -> String
}

public extension CurrencyType {

static var symbol: String? {
return formatter.currencySymbol
static var defaultFormattingStyle: NSNumberFormatterStyle {
return .CurrencyStyle
}

/**
Default implementation of the `NSDecimalNumberBehaviors` for
the currency. This uses `NSRoundingMode.RoundBankers` and the
Expand All @@ -87,22 +87,15 @@ public extension CurrencyType {
internal extension CurrencyType {

static func formattedWithStyle(style: NSNumberFormatterStyle, forLocale locale: NSLocale) -> NSDecimalNumber -> String {
__formatter.reset()
__formatter.locale = locale
__formatter.numberStyle = style
switch locale.currencyCode {
case .Some(let wrapped) where wrapped == code:
break
default:
__formatter.currencyCode = code
__formatter.currencySymbol = formatter.currencySymbol
__formatter.internationalCurrencySymbol = formatter.internationalCurrencySymbol
__formatter.currencyGroupingSeparator = formatter.currencyGroupingSeparator
__formatter.currencyDecimalSeparator = formatter.currencyDecimalSeparator
__formatter.maximumFractionDigits = formatter.maximumFractionDigits

}
return { __formatter.stringFromNumber($0)! }

let formatter = NSNumberFormatter()
formatter.locale = locale
formatter.numberStyle = style
formatter.maximumFractionDigits = scale
formatter.currencySymbol = symbol ?? locale.currencySymbol
formatter.currencyCode = code

return { formatter.stringFromNumber($0)! }
}
}

Expand Down Expand Up @@ -159,8 +152,12 @@ public protocol ISOCurrencyType: CurrencyType {
/// - returns: the currency code
var _code: String { get }

/// - returns: a number formatter for the currency in the current locale.
var _formatter: NSNumberFormatter { get }
/// - returns: the currency scale
var _scale: Int { get }

/// - returns: the currency symbol
var _symbol: String? { get }

}

public extension ISOCurrencyType {
Expand All @@ -172,12 +169,12 @@ public extension ISOCurrencyType {

/// The currency scale
static var scale: Int {
return formatter.maximumFractionDigits
return sharedInstance._scale
}

/// Returns a formatter from the shared instance
static var formatter: NSNumberFormatter {
return sharedInstance._formatter
/// The currency symbol
static var symbol: String? {
return sharedInstance._symbol
}

/**
Expand Down Expand Up @@ -221,22 +218,38 @@ public struct Currency {
public class Base {

public let _code: String
public let _scale: Int
public let _symbol: String?

init(code: String, scale: Int, symbol: String?) {
_code = code
_scale = scale
_symbol = symbol
}

public lazy var _formatter: NSNumberFormatter = {
convenience init(code: String) {
let locale = NSLocale(localeIdentifier: NSLocale.canonicalLocaleIdentifierFromString(NSLocale.localeIdentifierFromComponents([NSLocaleCurrencyCode: code])))
let symbol = locale.currencySymbol!

let fmtr = NSNumberFormatter()
let locale = NSLocale(localeIdentifier: NSLocale.canonicalLocaleIdentifierFromString(NSLocale.localeIdentifierFromComponents([NSLocaleCurrencyCode: self._code])))
fmtr.locale = locale
fmtr.numberStyle = .CurrencyStyle
fmtr.currencyCode = self._code
fmtr.currencyCode = code
fmtr.currencySymbol = locale.currencySymbol
return fmtr
}()

init(code: String) {
self._code = code

let scale = fmtr.maximumFractionDigits
self.init(code: code, scale: scale, symbol: symbol)
}

convenience init(locale: NSLocale) {
self.init(code: locale.objectForKey(NSLocaleCurrencyCode) as! String)
let code = locale.currencyCode!
let symbol = locale.currencySymbol

let fmtr = NSNumberFormatter()
fmtr.locale = locale

let scale = fmtr.maximumFractionDigits
self.init(code: code, scale: scale, symbol: symbol)
}
}

Expand Down
2 changes: 0 additions & 2 deletions Money/Shared/Locale.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

import Foundation

internal let __formatter = NSNumberFormatter()

/**
LanguageType provides an interface to retrieve
a language identifier.
Expand Down
2 changes: 1 addition & 1 deletion Money/Shared/Money.swift
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ extension _Money: CustomStringConvertible {
NSNumberFormatterStyle.CurrencyStyle.
*/
public var description: String {
return formattedWithStyle(.CurrencyStyle)
return formattedWithStyle(C.defaultFormattingStyle)
}
}

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![Build status](https://badge.buildkite.com/265eb9670a2ef6b73eebf37769a8455c402509f71f09c4f51e.svg?branch=development)](https://buildkite.com/blindingskies/money?branch=development)
[![codecov.io](https://codecov.io/github/danthorpe/Money/coverage.svg?branch=development&token=gI70muNOjA)](https://codecov.io/github/danthorpe/Money?branch=development)
[![Cocoapods Compatible](https://img.shields.io/cocoapods/v/Money.svg)](https://img.shields.io/cocoapods/v/Money.svg)
[![CocoaPods Compatible](https://img.shields.io/cocoapods/v/Money.svg)](https://img.shields.io/cocoapods/v/Money.svg)
[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)
[![Platform](https://img.shields.io/cocoapods/p/Money.svg?style=flat)](http://cocoadocs.org/docsets/Money)

Expand Down
Loading

0 comments on commit 621d6be

Please sign in to comment.