The MeasurementFormatter class provides formatted and localized representations of units and measurements. When catering to a global audience, you should present this data in local units. Suppose your app shows the end user a distance between two points. Assume that the distance is in imperial units: feet, yards and miles. When catering to a global audience, you should present this data in local units. Consider the following:
The distance between New York and Paris is 3,626.81 miles
In French, you would want to not only translate the string’s text, but also the measurement units therein contained:
La distance entre New York et Paris est de 5 836,78 km
Instead of attempting to write your own utility classes to perform these conversions, you should leverage the power of Apple’s Foundation.
When dealing with distance measurements, MeasurementFormatter does great work with zero configuration. By the time the user installs your app, the user’s device has a default locale. Working with the distance measurement above, we can convert to the user’s localized standard:
Continue reading %Using MeasurementFormatter in Swift%
by Clay Unicorn via SitePoint
No comments:
Post a Comment