【问题标题】:Use of SystemLocale method of NSLocale classNSLocale 类的 SystemLocale 方法的使用
【发布时间】:2023-03-16 22:05:01
【问题描述】:

我真的不明白systemLocale方法制作的实例对象有什么用,虽然一直都是nil。

你能用一个实际的例子来描述一下吗?

【问题讨论】:

  • 什么平台?该平台的版本是什么?
  • 在 OSX 和 IOS 的 Xcode 中

标签: ios objective-c macos foundation


【解决方案1】:

您可以使用 SystemLocat 获取货币甲酸盐、数字甲酸盐或许多其他东西。 这是一个例子

 NSNumberFormatter *currencyFormat = [[NSNumberFormatter alloc] init];
    NSLocale *locale = [NSLocale systemLocale];
    [currencyFormat setNumberStyle:NSNumberFormatterCurrencyStyle];
    [currencyFormat setLocale:locale];       
    NSLog(@"Current currencyCode : %@", [currencyFormat currencyCode]);

【讨论】:

  • 正如我之前所说,当我运行上面的代码时,我得到的只是 (null) ,除非我使用 'CurrentLocale' 而不是 'SystemLocale' 方法
  • 使用设备代替模拟器
猜你喜欢
  • 2011-09-28
  • 2012-06-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多