Apple's new programming language Swift just Killed Objective C

June 3, 2014
Posted in iOS, Swift

swift

Hi,

I just watched the presentation on Apple’s new programming language: Swift. This means the end for Objective C and it fundamentally changes the world of iOS programming.

Why?

It is much easier to learn and much easier to work with and so we will see it used by a lot more programmers.

About the Swift Language itself:

It looks like a modern scripting language that shares similarities to Python and other modern nimble languages. I just took a quick look at some Swift code and it is indeed much easier to learn than Objective C.

Take a look at this:

let label = "The width is "
let width = 94

For the constant (created with the keyword ‘let’) you don’t necessarily need to declare the type of data that your constant is holding (if you will) Swift is smart enough (many times) to detect the data type automatically. For example:
let width = 94

… It seems pretty clear the ’94’ above is an int and not a string.

When there are situations where the initial value of your constant does not provide enough information with regards to its’ type, then you can specify it’s value like so:

let explicitDouble: Double = 70

Casting Types with Swift:

Since it seems Swift is NOT loosely typed like PHP and JavaScript, you need to explicitly convert data types. So for example:

let label = "The width is "
let width = 94
let widthLabel = label + String(width)

In the above code, I had to convert my ‘width’ constant from an integer (I’m sure Swift set ‘width’ to int when we declared the constant) .. to a string using: String(width)

Anyway, I just started looking at this language 20 minutes ago and I have a lot to learn! But, from what I’ve seen so far, and from what I’ve seen with the new Xcode tools and Swift Playground (which gives you live feedback of your code) I think this could be a great language to learn and teach with.

More to come I think.

Stefan Mischook
killerPHP.com

Comments

Comments are closed.

To Top