我在NSLocale
数字或货币格式中使用了很多。例如我这样使用它:
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
// Config the NSNumberFormatter ...
formatter.groupingSeparator = [[NSLocale currentLocale] objectForKey:NSLocaleGroupingSeparator];
编译器总是给我警告:Multiple methods named 'objectForKey:' found
这在大型项目中真的很烦人(这种类型的警告有 20 多个)。我发现摆脱此警告的唯一方法是将类型转换为NSDictionary
:
formatter.groupingSeparator = [(NSDictionary *)[NSLocale currentLocale] objectForKey:NSLocaleGroupingSeparator];
这可行,但我不确定这是否会导致问题,因为[NSLocale currentLocale]
似乎不直接是NSDictionary
([[NSLocale currentLocale] class]
返回__NSCFLocale
)。
有没有更好的解决方案?