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

Rewrite for Xcode 9 & Swift 3.2 #84

Open
wants to merge 22 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
0753ad6
[MNY-79]: Removes old sources
danthorpe Sep 15, 2017
1c210a9
[MNY-79]: Adds new files with support for basic functions
danthorpe Sep 15, 2017
75c63f3
[MNY-79]: Reorgs tests; adds Comparable
danthorpe Sep 15, 2017
56449a8
[MNY-79]: Removes unneeded overrides
danthorpe Sep 15, 2017
c739d7b
[MNY-79]: Adds division operator and more floating point conformance
danthorpe Sep 20, 2017
88aff2b
[MNY-79]: Adds tests for ISOMoney
danthorpe Sep 20, 2017
a6bdee0
[MNY-79]: Adds currencies & money
danthorpe Sep 20, 2017
3452b07
[MNY-79]: Moves BaseCurrency
danthorpe Sep 20, 2017
b465429
[MNY-79]: Updates fastlane
danthorpe Sep 20, 2017
4cdd71b
[MNY-79]: Fixies iOS currencySymbol issue.
danthorpe Sep 20, 2017
202ef80
[MNY-79]: Fixes AppleTV sdk version in fastlane
danthorpe Sep 20, 2017
385fadc
[MNY-79]: Adds init(minorUnits:)
danthorpe Sep 21, 2017
cd9c72d
[MNY-79]: Adds amount property
danthorpe Sep 21, 2017
dd2f3d9
[MNY-79]: Makes types public
danthorpe Sep 21, 2017
795ac15
[MNY-79]: Adds formatting styles
danthorpe Sep 24, 2017
7e06233
[MNY-79]: Fixes Mac tests
danthorpe Sep 24, 2017
bd4d2f4
[MNY-79]: Fixes issue with extra )
danthorpe Sep 27, 2017
bd1b6f5
[MNY-79]: Adds a failing test where the number formatter scale is not…
danthorpe Sep 27, 2017
08d79ee
[MNY-79]: Fixes failing test for the currency maximum fraction digits
danthorpe Sep 27, 2017
2987735
[MNY-79]: Fixes issue with fractional units
danthorpe Sep 27, 2017
ed9ae11
[MNY-79]: Removes `.device` currency
danthorpe Oct 1, 2017
49d693d
[MNY-79]: Works around intValue NSDecimalNumber bug
danthorpe Feb 6, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[MNY-79]: Moves BaseCurrency
  • Loading branch information
danthorpe committed Sep 20, 2017
commit 3452b0762c18626e5cb7d3c97aa4bf22709e8dc8
41 changes: 41 additions & 0 deletions Sources/Currency.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,44 @@ extension Currency {
return Currency(code: code, scale: scale, symbol: locale.currencySymbol)
}()
}

// MARK: - Base Currency

extension Currency {

public class BaseCurrency: CurrencyProtocol, Equatable {

public static func ==(lhs: BaseCurrency, rhs: BaseCurrency) -> Bool {
return lhs.code == rhs.code
&& lhs.scale == rhs.scale
&& lhs.symbol == rhs.symbol
}

public let code: String
public let scale: Int
public let symbol: String?

init(code: String, scale: Int, symbol: String?) {
self.code = code
self.scale = scale
self.symbol = symbol
}

convenience init(code: String) {
let idFromComponents = NSLocale.localeIdentifier(fromComponents: [NSLocale.Key.currencyCode.rawValue: code])
let canonical = NSLocale.canonicalLocaleIdentifier(from: idFromComponents)
let nslocale = NSLocale(localeIdentifier: canonical)
let locale = Locale(identifier: canonical)
let symbol = nslocale.currencySymbol

let fmtr = NumberFormatter()
fmtr.locale = locale
fmtr.numberStyle = .currency
fmtr.currencyCode = code
fmtr.currencySymbol = symbol

let scale = fmtr.maximumFractionDigits
self.init(code: code, scale: scale, symbol: symbol)
}
}
}
64 changes: 0 additions & 64 deletions Sources/ISOMoney.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,67 +88,3 @@ extension ISOMoney: Comparable {
}
}


























extension Currency {

public class BaseCurrency: CurrencyProtocol, Equatable {

public static func ==(lhs: BaseCurrency, rhs: BaseCurrency) -> Bool {
return lhs.code == rhs.code
&& lhs.scale == rhs.scale
&& lhs.symbol == rhs.symbol
}

public let code: String
public let scale: Int
public let symbol: String?

init(code: String, scale: Int, symbol: String?) {
self.code = code
self.scale = scale
self.symbol = symbol
}

convenience init(code: String) {
let idFromComponents = NSLocale.localeIdentifier(fromComponents: [NSLocale.Key.currencyCode.rawValue: code])
let canonical = NSLocale.canonicalLocaleIdentifier(from: idFromComponents)
let nslocale = NSLocale(localeIdentifier: canonical)
let locale = Locale(identifier: canonical)
let symbol = nslocale.currencySymbol

let fmtr = NumberFormatter()
fmtr.locale = locale
fmtr.numberStyle = .currency
fmtr.currencyCode = code
fmtr.currencySymbol = symbol

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