ios - NSLocale 强制日历类型

标签 ios swift nslocale

[NSLocale currentLocale]可能会返回<__NSCFLocale: 0x7ff708516540> 'en_US@calendar=japanese'}

问题:我可以说 NSLocale 不附加 calendar=japanese到语言环境。

最佳答案

objective-C

   NSString *lang = [[NSLocale preferredLanguages] objectAtIndex:0];
   NSLog(@"language is %@", lang);

  NSString   *langua = [[NSLocale currentLocale] objectForKey: NSLocaleLanguageCode];
  NSLog(@" specified language is %@", langua);

  NSString   *countryCode = [[NSLocale currentLocale] objectForKey: NSLocaleCountryCode];
  NSLog(@"specified countryCode is %@", countryCode);

输出类似

enter image description here

swift

var lang = NSLocale.preferredLanguages()[0]

let langua = NSLocale.currentLocale().objectForKey(NSLocaleLanguageCode) as! String
let countryCode = NSLocale.currentLocale().objectForKey(NSLocaleCountryCode) as! String

关于ios - NSLocale 强制日历类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32986395/

相关文章:

ios - 有什么方法可以从 Apple Watch 访问加速度计吗?

ios - Xcode 删除图像顶部的一行

ios - 使用 xcode 和 swift 从照片库中选择要显示到 Apple Watch 上的 ImageView 的图像

swift - 如何将币种代码重命名为币种全称? swift

swift - NSDateformatter 可以用于读取瑞典月份吗

ios - 为什么lazy property和didSet会以递归调用结束?

iphone - 设置 UITabBarControllers 的 selectedIndex 属性后禁用自动旋转(SDK 错误?)

ios - 组 TableView 标题显示在 admob 横幅上

ios - 如何在核心数据中保存图像

ios - 如何将英语设置为 iOS 应用程序的默认语言?