如何在iOS中获取文件大小的本地化描述字符串?
以下是我的代码:如何在iOS中获取文件大小的本地化描述字符串?,ios,objective-c,localization,Ios,Objective C,Localization,以下是我的代码: - (NSString *)fileSizeDescriptionForFileAtPath:(NSString *)filePath { NSError* error; NSDictionary *fileDictionary = [[NSFileManager defaultManager] attributesOfItemAtPath:filePath
- (NSString *)fileSizeDescriptionForFileAtPath:(NSString *)filePath {
NSError* error;
NSDictionary *fileDictionary = [[NSFileManager defaultManager] attributesOfItemAtPath:filePath
error: &error];
NSNumber *size = [fileDictionary objectForKey:NSFileSize];
NSString *desc = [NSByteCountFormatter stringFromByteCount:size.longLongValue
countStyle:NSByteCountFormatterCountStyleFile];
return desc;
}
此代码是否能正确格式化任何本地化的文件大小
我在NSByteCountFormatter
文档中没有找到格式化字符串本地化的参考
谢谢你的建议。因此,我尝试了上面的代码和几个区域设置,结果看起来完全本地化了。因此创建一个
NSByteCountFormatter
,将其设置为NSByteCountFormatterCountStyleFile
,将系统区域设置为不同的内容,然后尝试。NSByteCountFormatter
上的文档确实提到某些设置可能对某些地区无效,这至少意味着它支持地区。然而,NSByteCountFormatter
似乎没有区域设置属性,这是令人惊讶的。顺便说一句,在阅读您的文章之前,我从未听说过NSByteCountFormatter
。谢谢你提醒我。(投票)在发布这样的问题之前,你需要自己尝试一下。这比发布这个问题要快得多。