This is a quick writeup on a delightful little gem I found While creating a calculation app. Inside Foundation framework with iOS 10 there is now a structure called Measurement, which takes a value and a unit. The units come from a whole host of categories such as volume, length, mass, and many more. As I come from an engineering background, this fills me with joy. I’m not even sure how often, I will use it, but it just makes me happy. So here’s how you can use it!
Enough Already, Just get to it!
Say you want to convert feet to inches. Well that can be done as simple as this:
let inches = feet.converted(to: .inches)
Well that was easy, perhaps you want to know what 1g on earth is?
let metersPerSecondSquared = acceleration.converted(to: .metersPerSecondSquared)
I can keep going all day with this, but hope this last example demonstrates all the units that are available. There are literally tons. Just type ‘Unit’ and let autocomplete guide you.