Kicking off the Swift way

Kicking off the Swift way

Starting a project with a new programming language always generates chills in companies, no matter what size. Team leaders (more often than coders) tend to feel reluctant to embark on a new project with tools that haven’t been out in the market for a considerable time for obvious reasons.

In my very first week at Bundle, I remember discussing with Kelvin how we would bring his vision, and Anna’s designs to life. We understood that selecting the programming language with which we code the iOS app would have huge implications on the future of the project.

Whilst I was eager to learn and ship a product made with Swift, Kelvin was excited with taking the development of Bundle into new territory, and thankfully our decision to choose Swift over Objective-C has proved a fruitful one.

So why should you kick start your project using Swift?

Swift is a programming language developed by Apple since 2010 and introduced at WWDC 2014. It replaced the tedious, archaic syntax in which Objective-C is constrained, by taking the best features of other OOP languages out there as Ruby, Python and C# that we programmers love, and blending it with Apple’s own culture. Throughout this year, the general opinion has been highly positive, with a vast majority of coders willing to launch projects in this new language. In the following lines I will describe some of the features that make Swift a great choice.

Consistency

The new syntax in Swift is brutally concise. Take as an example the same declaration in Objective-C and Swift:

// Objective C

UIView *myView = [[UIView alloc] initWithFrame: aFrame];

// Swift:

let myView = UIView(frame: aFrame)

In this single line we can notice several things:

  • There’s no need of redundancy in declaration, we know it’s a UIView class, we don’t need to write it down twice!
  • We got rid of the “ * “. We know that they are pointers to objects (if not, the compiler will remind you)
  • There’s no unnecessary square brackets framing everything
  • Notice there’s no semicolon, because it’s not needed!
  • We use “let” to declare constants, a slight but powerful optimisation

I have experienced a big change in how my code looks. Now it’s much easier to read and understand, which implies less coding time and less bugs.

Interoperability

For those worried about having to dump their good ol’ libraries and classes: don’t panic. The interoperability between Objective-C and Swift is seamless. Apple has dedicated a big effort to making this connection as smooth as possible, with great results. Just by setting up a bridging header between the two environments Xcode allows an effortless communication between them. Just keep in mind that some of the amazing functionalities introduced in Swift are not backwards compatible if you plan to use them in Objective-C.

Open Source

At WWDC 15 we received the exciting news about Swift going Open Source. It represents a bold move, but definitely in the right direction. There are many impressive open source communities that have leveraged the rapid establishment of programming languages or frameworks. Django for example, has acquired a huge presence around the globe with a vertiginous speed, impulsed and maintained mainly by the OS community. I believe that Swift will benefit greatly with the help of the OS community and will evolve in the near future.

Final words

After all this time working with Swift I feel satisfied that I made the right decision at the beginning of the project. It is an awesome programming language, designed for the applications of tomorrow. It takes the best features from other languages, but still maintains its own character, the Swifty way. It is concise and clear to read and write, and far easier to debug than old Objective-C. It is helping me build professional and neat code without struggling with the compiler. And the best of all, it’s heading down the open source track.

Bernardo Santana

About Bernardo Santana

Software Engineer, Mobile Developer and iOS enthusiast from Venezuela.