Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在iOS中获取文件大小的本地化描述字符串?_Ios_Objective C_Localization - Fatal编程技术网

如何在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
。谢谢你提醒我。(投票)在发布这样的问题之前,你需要自己尝试一下。这比发布这个问题要快得多。