Why swift Developers should learn Objective-C First

Over the last few weeks I’ve been asked the question a lot – how do I learn Swift? Should I learn it now?

SwiftTour_2xAspiring iOS developers should begin with Objective-C, Apple’s traditional language for iOS programming.  Now you might be asking, “why, Apple just released Swift!?!”  Well, Swift does indeed look deceptively simple – one might even compare it to JavaScript, and its syntax is very similar. However, Swift is built o the same framework as Objective-C, Cocoa Touch, and uses many o the design patterns taught in Objective-C programming.  If you have a strong grasp on Objectove-C, taking the jump to Swift will be a breeze, however, for those who have no experience in Objective-C, learning Apple’s older language will give you a strong handle on Swift.

Objective-C isn’t going anywhere anytime soon.  In fact, it’ll be around for a long time. There’s currently 1.2 Million iOS apps written in Objective-C on the app store and countless other Mac apps also written in Objective-C.  As such, it’s not leaving us.

Sadly, because of the Apple NDA (non-discosure agreement), developers can’t post video tutorials or screenshots of beta software for other iOS developers to learn swift.  We can, however, produce tutorials but have to be careful what he show off in those tutorials.  Because of the NDA, resources for Swift will be limited until Apple lifts it in the Fall.

So my suggestion to aspiring iOS developers: learn Objective-C and get a good handle on it. Then make the jump to swift – everything will make a lot more sense!   Happy learning!

Advertisements

Basics

Hey again, let’s dive deeper into Swift. Power up your Xcode playground and let’s get going!

Creating a Variable

var myVariable = "Hello"

Using the var keyword, you can define a variable as in JavaScript.  The var keyword accepts various types (int, BOOL, float, etc).  By default, the word Hello is a string (a line of text) because it is enclosed in double quotes.  However, what if you didn’t want a string? Perhaps you want to set a number.

var myVariable = 3

You can also create a  string (or any other type for that matter), my explicitly declaring it a string.  Let’s check that out.

var myVariable: String = "Hello"

That’s the same as the first line of code. As such, you can also define a double in the same manner.

var myVariable: Double = 5.0

Easy? It’s quite simple!

Creating a Constant

Use the let keyword to define a constant.  Let;s take a look at an example.

let myVariable = 2

Bam, there’s a constant. See the below code for defining a BOOL.

var myVariable = true

Swift Part 1

Yosemite

On June 2, Apple shocked the world with the introduction of Swift, a revolutionary new programming language designed to make it easier to write beautiful Mac and iOS apps.  Swift works with Objective-C and the Cocoa frameworks so implementing it shouldn’t be a problem.  Today, we’re going to look into Swift and see how it works.

Let’s get going!