更新时间:2023-02-21 08:38:23
参见 Wojciech N. 的回答寻求更简单的解决方案!
See Wojciech N.'s answer for a simpler solution!
与NSLocale Swift 3类似,您必须转换覆盖类型Locale
回到它的基础对应 NSLocale
以检索国家/地区代码:
Similarly as in NSLocale Swift 3, you have to cast the overlay type Locale
back to its
Foundation counterpart NSLocale
in order to retrieve the country code:
if let countryCode = (Locale.current as NSLocale).object(forKey: .countryCode) as? String {
print(countryCode)
}