NSLengthFormatter: Should Allow for Preferred Unit

Originator:SlaunchaMan
Number:rdar://20415783 Date Originated:03-Apr-2015 12:13 PM
Status:Open Resolved:
Product:iOS SDK Product Version:Xcode 6.2 (6C131e)
Classification:Feature (New) Reproducible:Always
 
Summary:
When using an NSLengthFormatter, it’s great that the default value will convert from meters to an automatically-selected unit, but there are cases when another unit would be preferred, and it’d be nice to have NSLengthFormatter take care of that conversion.

Steps to Reproduce:
1. Create an NSLengthFormatter.
2. Use -stringFromMeters with 402.336 meters, or a ¼ mile.

Expected Results:
The output is 0.25 miles.

Actual Results:
The output is 439.99 yards.

Notes:
Right now, this is possible by doing the conversion yourself:

double miles = meters * 0.00062137;

[self.lengthFormatter stringFromValue:miles
                                 unit:NSLengthFormatterUnitMile]; // 0.25 miles

But since NSLengthFormatter already has logic for converting between units built-in, it would be swell to do something like this:

self.lengthFormatter.preferredUnit = NSLengthFormatterUnitMile;

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!