From f21a0db45ede01d21cc597bf67c64e7c4e84d2a6 Mon Sep 17 00:00:00 2001 From: RandomHashTags Date: Wed, 19 Oct 2022 23:48:24 -0500 Subject: [PATCH] `getCurrencies` was added to `SovereignRegion` --- Sources/SwiftSovereignStates/Country.swift | 2 +- .../SwiftSovereignStates/SovereignRegion.swift | 2 ++ Sources/SwiftSovereignStates/SovereignState.swift | 4 ++-- .../SwiftSovereignStates/SovereignStateCity.swift | 3 +++ .../SovereignStateSubdivision.swift | 3 +++ .../internal/SovereignStateCurrencies.swift | 15 ++++++++++++--- 6 files changed, 23 insertions(+), 6 deletions(-) diff --git a/Sources/SwiftSovereignStates/Country.swift b/Sources/SwiftSovereignStates/Country.swift index 97b4fb5..dc5ecde 100644 --- a/Sources/SwiftSovereignStates/Country.swift +++ b/Sources/SwiftSovereignStates/Country.swift @@ -546,7 +546,7 @@ public enum Country : String, CaseIterable, SovereignState { return SovereignStateTimeZone.get(self) } /// The official currencies used within this country. - public func getCurrencies() -> [Currency]? { + public func getCurrencies() -> [Currency] { return SovereignStateCurrencies.get(self) } diff --git a/Sources/SwiftSovereignStates/SovereignRegion.swift b/Sources/SwiftSovereignStates/SovereignRegion.swift index 743825c..b2f2916 100644 --- a/Sources/SwiftSovereignStates/SovereignRegion.swift +++ b/Sources/SwiftSovereignStates/SovereignRegion.swift @@ -40,6 +40,8 @@ public protocol SovereignRegion : Codable, Hashable, LosslessStringConvertible { func getWikipediaURLPrefix() -> String? func getWikipediaURLSuffix() -> String? + /// The official currencies used within this SovereignRegion. + func getCurrencies() -> [Currency] /// All the time zones this SovereignRegion recognizes within its administrative borders. func getTimeZones() -> [SovereignStateTimeZone]? /// All temperate zones this SovereignRegion contains within its administrative borders. diff --git a/Sources/SwiftSovereignStates/SovereignState.swift b/Sources/SwiftSovereignStates/SovereignState.swift index c7c08a6..b054121 100644 --- a/Sources/SwiftSovereignStates/SovereignState.swift +++ b/Sources/SwiftSovereignStates/SovereignState.swift @@ -8,9 +8,9 @@ import Foundation public protocol SovereignState : SovereignRegion { - /// The ISO 3166-1 alpha-2 code for this SovereignRegion. Country codes are defined at https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2 . Subdivision codes are defined at https://en.wikipedia.org/wiki/ISO_3166-2. + /// The ISO 3166-1 alpha-2 code for this SovereignState. Country codes are defined at https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2 . Subdivision codes are defined at https://en.wikipedia.org/wiki/ISO_3166-2 . func getISOAlpha2() -> String? - /// The ISO 3166-1 alpha-3 code for this SovereignRegion. Country codes are defined at https://en.wikipedia.org/wiki/ISO_3166-1_alpha-3 . + /// The ISO 3166-1 alpha-3 code for this SovereignState. Country codes are defined at https://en.wikipedia.org/wiki/ISO_3166-1_alpha-3 . func getISOAlpha3() -> String? } public extension SovereignState { diff --git a/Sources/SwiftSovereignStates/SovereignStateCity.swift b/Sources/SwiftSovereignStates/SovereignStateCity.swift index 9bca608..f45a578 100644 --- a/Sources/SwiftSovereignStates/SovereignStateCity.swift +++ b/Sources/SwiftSovereignStates/SovereignStateCity.swift @@ -137,6 +137,9 @@ public extension SovereignStateCity { func getCacheID() -> String { return getSubdivision().getCacheID() + "_" + getIdentifier() } + func getCurrencies() -> [Currency] { + return getSubdivision().getCurrencies() + } func getDefaultType() -> SovereignStateCityType { return SovereignStateCityType.city diff --git a/Sources/SwiftSovereignStates/SovereignStateSubdivision.swift b/Sources/SwiftSovereignStates/SovereignStateSubdivision.swift index 79e4ca4..5bd4d29 100644 --- a/Sources/SwiftSovereignStates/SovereignStateSubdivision.swift +++ b/Sources/SwiftSovereignStates/SovereignStateSubdivision.swift @@ -158,6 +158,9 @@ public extension SovereignStateSubdivision { func getISOAlpha3() -> String? { return nil } + func getCurrencies() -> [Currency] { + return getCountry().getCurrencies() + } func getWikipediaURLSuffix() -> String? { return "_" + getTypeSuffix() diff --git a/Sources/SwiftSovereignStates/internal/SovereignStateCurrencies.swift b/Sources/SwiftSovereignStates/internal/SovereignStateCurrencies.swift index e7dc0dd..208ce4b 100644 --- a/Sources/SwiftSovereignStates/internal/SovereignStateCurrencies.swift +++ b/Sources/SwiftSovereignStates/internal/SovereignStateCurrencies.swift @@ -8,7 +8,7 @@ import Foundation internal enum SovereignStateCurrencies { - static func get(_ country: Country) -> [Currency]? { + static func get(_ country: Country) -> [Currency] { switch country { case .abkhazia: return [Currency.RUB] case .afghanistan: return [Currency.AFN] @@ -256,12 +256,21 @@ internal enum SovereignStateCurrencies { case .zambia: return [Currency.ZMW] case .zimbabwe: return [Currency.ZWL] - case .vatican_city: return [Currency.EUR] case .wallis_and_futuna: return [Currency.XPF] case .western_sahara: return [Currency.MAD] - default: return nil + + case .curacao: return [Currency.ANG] + case .equatorial_guinea: return [Currency.XAF] + case .french_polynesia: return [Currency.XPF] + case .isle_of_man: return [Currency.GBP] + case .kosovo: return [Currency.EUR] + case .new_caledonia: return [Currency.XPF] + case .northern_cyprus: return [Currency.TRY] + case .scotland: return [Currency.GBP] + case .somaliland: return [Currency.SLS] + case .united_states_virgin_islands: return [Currency.USN, Currency.USD] } } }