Last active
August 29, 2015 14:26
-
-
Save daehn/97430090ddf034bf8963 to your computer and use it in GitHub Desktop.
Struct containing the displayNames and codes for the common ISO currency codes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Currency { | |
let code, displayName: String | |
init?(code: String?) { | |
if let code = code, | |
displayName = NSLocale.systemLocale().displayNameForKey(NSLocaleCurrencyCode, value:code) { | |
self.code = code | |
self.displayName = displayName | |
} else { | |
return nil | |
} | |
} | |
} | |
struct CurrencyDataSource { | |
let currencies: [Currency] = { | |
// The first `map` can be replaced with `flatMap` in Swift 2.0 | |
// to remove the `filter` and `map` calls afterwards | |
NSLocale.commonISOCurrencyCodes().map { | |
return Currency(code: $0 as? String) | |
}.filter { $0 != nil }.map { $0! } | |
}() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment