更新时间:2023-02-21 08:34:05
请参阅 Wojciech N.回答
以获得更简单的解决方案!
与 NSLocale Swift 3 ,您必须投射叠加类型区域设置
回到
基金会对应 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)
}