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…]

Objective-C and Swift Comparison

This week I thought I would share some notes I took on the differences between Objective-C and Swift at basic level. IE chapter one of Apple’s Swift Programming Language iBook. I encourage you to go download it for free if you haven’t already.

The set of note offered here were just some notes I took while reading the first chapter, I haven’t gone back and edited so proceed with caution.

Anyway, without further ado:

Objective-C and Swift Comparison

Swift Optionals

As an Objective-C developer, the biggest point of confusion for me was with optionals. There are of course other tricky idiosyncrasies, but the hardest thing to wrap my head around was the use of optionals and what the hell “?”,”!”, and “??” means.

Why We Needed Optionals

If you are at all familiar with objective-C , then your well aware that every object had the option of returning nil. To make code safe, we had to typically check for nil all of the time. Often we would set a return nil when something went wrong as well. So we would end up with a bunch of ugly code that looked something like this:

[Read more…]

State of The Union

The presidential state of the union is a designated time where the president can openly complain about his views on the world and update us all on what is going on in his world. Since that is basically what I’ll be doing in this article, that is the title I gave it.

A Brief History

I had spend quite a bit of my free time for roughly a year or two learning Objective-C. Granted, had my day job been working on Apps, I could have learned it a bit quicker. Now that I am a gainfully employed iOS developer I have a few more years of experience under my belt. So imagine my frustration when a new programming language emerges just as I was starting to touch on Objective-C Mastery.

I started NSCookbook with a basic goal. NSCookbook was a method of teaching myself iOS Development while also providing value to the community. I have always found that the best way to learn something is to teach someone else how to do it. As a noob myself, I felt I had a unique perspective that would help out the new comers. What I liked about learning iOS development is everything was new to me and it was fun. Now that I’m more experienced, most of what I will write now is something I already have a pretty good grasp on. In other words, It’s getting a bit boring to me. This is where Swift will help me out.

The State of Swift

Swift 1.1 came out with XCode 6.0 and iOS 8. At the time I had guessed that Swift would not be quickly adopted as it was relatively new and buggy. None-the-less, folks adopted Swift in surprising numbers. As of Today, Swift 2.0 is the current version, and is quickly becoming the standard iOS language. This has become an increasingly cumbersome fact for an Objective-C developer for the following reasons:

  1. Every time I’m trying to solve problem that is new in iOS 8 or iOS 9, Most of the solutions that come up in stack overflow are now swift.
  2. New libraries on Apple’s documentations are documented in Swift
  3. Playgrounds are really sweet for experimenting, and they don’t support Objective-C
  4. Once you see Swift, you may realize how much more ugly Objective-C is.

So What Now?

I have noticed That I have been increasingly lazy with respect to my articles. This is mostly because I don’t like the idea of showing both Swift and Objective-C. It’s a lot of damn work, and half of it is largely uninteresting to me. Therefore, Moving forward I’m going to Ditch Objective-C. My primary objective right now is to learn swift. As such, I’d rather not waste too much time with Objective-C. I will however attempt to update old articles that are still applicable with Swift. I hope ya’ll are okay with that. 🙂

css.php
Privacy Policy