The string() method of the MeasurementFormatter class doesn't work

Hi. I just filed a bug but I want to see if someone knows something about this. I was experimenting with the MeasurementFormatter class presented in the talk 238 of the last WWDC (https://developer.apple.com/videos/play/wwdc2016/238/) and I found that the string() method of this class doesn't take units created from subclasses of Dimensions, like UnitLength. For example, the following code presented in the talk returns an error in Xcode 8 8S128d.


let formatter = MeasurementFormatter()
let distance = Measurement(value: 5, unit: UnitLength.kilometers)
let result = formatter.string(from: distance)


This is an example from the talk, so it should work. The only way I've found to hide the error is to cast the unit as Unit when the Measurement structure is initialized.


let formatter = MeasurementFormatter()
let distance = Measurement(value: 5, unit: UnitLength.kilometers as Unit)
let result = formatter.string(from: distance)


Is this a bug or normal behaviour from now on?


Thanks

JD

Replies

I'm following this as well. Looks like it's still an issue in Xcode 8 beta 2. I found this link: https://bugs.swift.org/browse/SR-1891 Hopefully it'll be fixed soon.

This now works for me in Xcode 8.0 beta 4.