Archives for March 2017

Last updated by at .

Quick Measurement Conversion

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 feet = Measurement(value: 5, unit: UnitLength.feet)
let inches = feet.converted(to: .inches)

Well that was easy, perhaps you want to know what 1g on earth is?

let acceleration = Measurement(value: 1, unit: UnitAcceleration.gravity)
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.

Cheers!

css.php
Privacy Policy