如何从MeasurementFormatter 结果中获取本地化的单位符号?

Dan*_*avo 6 ios swift measurementformatter

我正在尝试获取使用测量格式化程序获得的任何测量的本地化单位符号。

\n\n

例如,如果区域设置使用华氏度,但应用程序以摄氏度存储其数据,我将创建一个测量格式化程序,如下所示:

\n\n
let formatter = MeasurementFormatter()\nlet measurement = Measurement(value: 10, unit: UnitTemperature.celsius)\nformatter.string(from: measurement)\n
Run Code Online (Sandbox Code Playgroud)\n\n

最后一行将为我提供“50\xc2\xb0F”。\n现在我想从测量中获取“\xc2\xb0F”值。

\n\n

我尝试过使用

\n\n
formatter.string(from: measurement.unit)\n
Run Code Online (Sandbox Code Playgroud)\n\n

但这只给了我“摄氏度”

\n\n

提前致谢!

\n

小智 -4

为了获得“\xc2\xb0F”,我认为您必须将格式化程序的区域设置设置为“en_US”。

\n