How do I know which is the default measure system (imperial or metric) on iOS?

前端 未结 6 1466
旧时难觅i
旧时难觅i 2020-12-07 22:15

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 m

6条回答
  •  醉话见心
    2020-12-07 22:45

    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:

    import Foundation
    
    let locale = Locale(identifier: "EN_UK")
    locale.usesMetricSystem // true!
    var formatter = MeasurementFormatter()
    formatter.locale = locale
    formatter.string(from: Measurement(value: 1000, unit: UnitLength.meters)) // 0.621 mi
    

    To render a distance as a string in local, natural unit, use:

    let distanceInMeters: CLLocationDistance = 1000
    let formatter = MeasurementFormatter()
    formatter.string(from: Measurement(value: distanceInMeters, unit: UnitLength.meters)) // 0.621 mi
    

    Official documentation: https://developer.apple.com/documentation/foundation/measurementformatter

提交回复
热议问题