NSLocale
has a method called - objectForKey:
that returns an object corresponding to a specified
NSLocale
component key passed as a parameter. With Swift 2.2, - objectForKey:
has the following declaration:
func objectForKey(_ key: AnyObject) -> AnyObject?
Among the many NSLocale
component keys, Apple states about NSLocaleCurrencyCode
:
The key for the currency code associated with the locale. The corresponding value is an NSString
object; for example, "USD".
Therefore, you can retrieve the currency code linked to a NSLocale
instance with the following Swift 2.2 and Swift 3 code snippets:
Swift 2.2
import Foundation
let locale = NSLocale(localeIdentifier: "fr_FR")
//let locale = NSLocale.currentLocale()
let localeCurrencyCode = locale.objectForKey(NSLocaleCurrencyCode) as! String
print(localeCurrencyCode) // prints "EUR"
Swift 3
import Foundation
let locale = Locale(localeIdentifier: "fr_FR")
//let locale = Locale.current
let localeCurrencyCode = locale.object(forKey: Locale.Key.currencyCode) as! String
print(localeCurrencyCode) // prints "EUR"