Could you please help on how to get country code using NSLocale
in Swift 3
?
This is the previous code I have been using.
N
NSLocale.countryCode
is the same as Locale.regionCode
This is from Locale.swift
/// Returns the region code of the locale, or nil if it has none.
///
/// For example, for the locale "zh-Hant-HK", returns "HK".
public var regionCode: String? {
// n.b. this is called countryCode in ObjC
if let result = _wrapped.object(forKey: .countryCode) as? String {
if result.isEmpty {
return nil
} else {
return result
}
} else {
return nil
}
}