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!

Some Things I Learned With Swift

 

Lately I’ve been hard at work learning the in and outs of Swift 3. Now that I’ve finished 3 apps in the language I feel comfortable enough to share a few things I’ve learned in Swift.

Organization

I can’t say whether or not what I’ve been doing in terms of organization is best practice but it looks neat to me, and for the time being, that’s good enough.

Extensions are Sweet

In swift, Extensions are so easy to implement I find myself using them every where. Mostly I’ll use them inside a class to separate portions of code. In Objective-C I would have used the #pragma mark, but in Swift I tend to use the // MARK: – combined with and extension for new sections of code. I’ll typically make a section for properties, styling, and actions to name a few.
[Read more…]

css.php
Privacy Policy