How do you specify the locale/language for an NSFormatter that doesn't have a locale property?

妖精的绣舞 提交于 2019-12-07 10:54:14

问题


There are a lot of specialized subclasses of NSFormatter:

CNContactFormatter
CNPostalAddressFormatter
DRMSFFormatter
MKDistanceFormatter
NSByteCountFormatter
NSDateComponentsFormatter
NSDateFormatter
NSDateIntervalFormatter
NSEnergyFormatter
NSLengthFormatter
NSMassFormatter
NSNumberFormatter
NSPersonNameComponentsFormatter

Most of us have used NSNumberFormatter and NSDateFormatter. Those have a locale property that lets you specify what locale to use when converting from strings to/from the "native" format the formatter supports. Some others like NSDateComponentsFormatter inherit their locale from one of their properties (NSDateComponentsFormatter uses the locale of the specified calendar, if any.)

Most of the others don't seem to have any way to specify a locale. The only way I can think of to get them to generate output in a specific language/locale is to set the system locale, get the output/convert a string to numeric format, and then set it back.

Is there a way to set the locale for formatters like NSByteCountFormatter that don't seem to offer a locale setting of any kind?

来源:https://stackoverflow.com/questions/36532331/how-do-you-specify-the-locale-language-for-an-nsformatter-that-doesnt-have-a-lo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!