How to Parse a String to get a Measurement (Opposite of MeasurementFormatter)

Viewed 196

Apple has provided us a fairly nice way to get from a Measurement to a string:

MeasurementFormatter().string( from: measurement )

I'm trying to go the opposite direction: given a string provided by a user, I'd like to parse it and turn it into a Measurement object. [E.g., convert "2cm" into Measurement(value: 2.0, unit: UnitLength.centimeters)]

Does Apple provide any help here, or does anybody know of a library that does this already?

0 Answers
Related