How do I know which is the default measure system (imperial or metric) on iOS ?
How do I get this preference from the device settings, so I know what to display in my app ?
thanks
How do I know which is the default measure system (imperial or metric) on iOS ?
How do I get this preference from the device settings, so I know what to display in my app ?
thanks
The
NSLocale
can tell you:Only three countries do not use the metric system: the US, Liberia and Myanmar. The later uses its own system, the former two use Imperial Units.
Apples documentation says (emphasis mine):
here's a swift version
For swift 3
As others mentioned before, the UK uses a mix of metric and imperial units.
I would recommend using the new
MeassurementFormatter
introduced in iOS 10 which handles most of these discrepancies:To render a distance as a string in local, natural unit, use:
Official documentation: https://developer.apple.com/documentation/foundation/measurementformatter
@DarkDust answer for swift3
You should probably just have a setting in your app and let your users choose -- this is what Apple does in the Weather app.
If you want to choose a sensible default you could look at the locale. If it's US, pick imperial otherwise choose metric. It is a heuristic, it will be wrong sometimes, but it's just a default that can be changed.