Changing the locale on a MeasurementFormatter resets its numberFormatter

Originator:regexident
Number:rdar://35529182 Date Originated:14-Nov-2017 13:22
Status:Open Resolved:
Product:iOS + SDK Product Version:iOS 10.0+
Classification:Other Bug Reproducible:Always
 
Summary:
Changing the locale on a MeasurementFormatter resets its numberFormatter. This is neither desired, nor documented anywhere and I just wasted way too much time trying to figure this out.

Steps to Reproduce:
1. Run this:

```
import Foundation

let formatter = MeasurementFormatter()
formatter.numberFormatter.minimumFractionDigits = 2
formatter.numberFormatter.maximumFractionDigits = 2
// formatter.locale = Locale(identifier: "en_US")
let measurement: Measurement<UnitDuration> = .init(value: 1234.56789, unit: .seconds)

let string = formatter.string(from: measurement)
assert(string == "1234.57 sec")
```

2. Remove the “//“ from “// formatter.locale” and run it again. See it fail.

Expected Results:
Changing locale retains changes made to formatter’s numberFormatter. Or at least a note in the docs that it doesn't retain formatting.

Actual Results:
Changing locale resets formatter’s numberFormatter.

Version:
iOS 10.0+

Notes:

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!