This week we’re taking a look at the new Measurement API: a new part of the Foundation framework. On the face of it, it doesn’t look all that exciting: it provides a mechanism to convert between units such as miles and kilometers.
However, when you think about it, we spend an awful lot of time transforming values. This might be because you have an angle in degrees, but the API you’re using to rotate a view requires the angle in radians. Alternatively, it may be because your application calculates distances in miles, but you need to convert into kilometers for your users who prefer to use that unit.
Before iOS 10, you may have created your own functions to transform values to another unit or used an external library. Now Apple have provided an API to handle most of the heavy lifting for you, so let’s take a look and see what it can do!