Apple Swift Programming Language

03 Jun 2014
by Admin

Well, you probably heard about it already. Apple unveiled a new language called Swift at yesterday’s WWDC.

What, a new language you say?

Yes, indeed, a new language. To understand why they’d rock the ecosystem so much and force you to reopen you grey matter, it helps to take a look at the history of the current set of development tools.

As you know, developing natively for iOS is done using xcode and Objective-C. XCode is actually quite a nice and rich IDE. The real issue comes with Objective-C. C is around 40 years old (Who hasn’t read Kerningham and Richie) and Objective-C isn’t much newer. It’s claim to fame was during Jobs’ respite from Apple when he founded NExT…and in fact, Objective-C is still littered with NExT remnants, such as NSString etc. In short, the language hasn’t evolved a whole lot and we’re carrying a lot of legacy baggage with it. People have also said Objective-C has mysterious syntax, what with all the [[‘s.

So, enter Swift.

The first major difference between Swift and Objective-C is the fact that Swift is a scripting language. Meaning you can interactively execute code, interrogate variables, make changes etc. My simplistic explanation is think of coding permanently in debug mode 🙂 Scripting languages have become popular…originally they were frowned upon for performance reasons but optimizations have largely voided that argument. Python is a great example of a successful scripting language.

So xcode introduces a new concept called Playgrounds which will let Swift developers essentially visualize their script in real-time while coding. Generally speaking, developing in a scripting language should make the development process faster than traditional compiled code. (Note, I said development time, not runtime).

Swift promises a slew of new benefits including closures (yeah ok, Objective-C did have that with Blocks), multiple return types, Generics, namespaces…um yeah ok, not all unique and new, but we can assume it is a capable platform built for the modern day operating system.

One of the first questions people had was “Can I still use Objective-C” – and the answer is yes. However, it is likely that Apple will be pushing hard to move the developer community over to Swift as the de facto standard going forward.

Here is a snippet of Hello World in Swift:

// Playground – noun: a place where people can play
var s = “Hello” + ” World.”

import Cocoa

let hero = NSImage(name: “myimage”);
let images = [“round, “star”, “heart”].ma[ {
NSImage(named: $0)

What you don’t see in above is that with Xcode, on the right hand side you’d see the results of each statement live as if it executed. That is the cool part about the playgrounds and it being a scripting language. Personally, the syntax will still need to grow on me – you do not need to use the ‘let’ syntax fortunately. Oh, and wait..I started talking about the legacy NS prefixes and guess what, they’re still there 🙁

Apple claims that Swift was designed to be fast. And remember, it is a scripting language during the development cycles but then turned into native optimized code for deployment.

All in all, I think this will be a good thing. Yes, we need to learn a new language. But let’s face it. It’s really only syntax. Logic is still logic. True still equals !False. And on the bright side, you can’t see job descriptions requiring 5 years of Swift on iOS.

© 2017