How do you specify the locale/language for an NSFo

2019-05-09 04:58发布

问题:

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?