Why You Shouldn’t Embrace Swift with Open Arms Just Yet

It’s been one year since Apple announced Swift on 2 June 2014, a language that made iOS developers around the world jump in their seats, and either cry heresy or embrace it with open arms.

Over the past year, Swift has gained immense popularity across the programming community rapidly, mostly because it looks similar to many script-like dynamic programming languages like Python, which makes reading and writing code significantly faster and easier.

I’m here to convince you that as efficient and reliable as Swift may be, it is still critical for developers to have an understanding of Objective C, especially so if they are new to the iOS development environment.

Disclaimer: I am not saying that you shouldn’t learn or code in Swift. Swift is a powerful language and is definitely the future of iOS development. I’m saying that you should learn Objective C, and then learn Swift.

Objective C is more explicit than Swift.

Objective C is an explicit language, which means that to get the same thing done, you’ll end up typing more code in Objective C than you normally would in Swift. Before you start wondering how in the world that could be a good thing and decide to stop reading the article, let me explain why.

When a language is more explicit, there is less room for confusion. It is crucial that you have an understanding of what the code that you type is going to do. Objective C forces you to understand what’s actually going on in the core of your code. This makes a huge difference if you’re new to programming or iOS development, because you’re more likely to have a deeper understanding of your code, and become a better programmer or developer.

It makes an even bigger difference when you’re looking at someone else’s code instead of your own, as you need to discern how that code ties in with the rest of the code, which brings me to my next point. Ask any Objective C programmer, and he will tell you that its verbosity is what makes the code so readable.

I saw this example somewhere, and I thought it was quite relevant to the point I’m trying to make.

// Objective C
NSArray *unsortedArray = @[@”Apple”, @”Orange”, @”Pear”];
NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:nil ascending:NO selector:@selector(localizedCompare:)];
NSArray *sortedArray = [unsortedArray sortedArrayUsingDescriptors:[NSArray arrayWithObject:sortDescriptor]];
// Swift
let fruits = ["Apple", "Orange", "Pear"]
reversed = sort(fruits, {>})

Both codes achieve the same result, an array of strings sorted in descending order. And while the Swift code achieves this with fewer lines of code, a programmer would probably find the Objective C code easier to understand in comparison if he saw both for the first time.

Most frameworks are written in C or Objective C.

In iOS development, you will definitely need to use Cocoa Touch frameworks such as Foundation and UIKit (both written in Objective C), which are used to do things like create objects and views, and handle user interaction. Or Core frameworks such as Core Graphics and Core Text (both written in C), which is used to draw shapes and text. When you create a project in Swift, these frameworks are not changed. Instead, types and concepts are essentially being remapped to their Swift counterparts (eg. id to AnyObject).

This can be a problem when you want to really look under the hood to understand how a method works at its core. It will most likely be written in C or Objective C, and if you only know Swift, you’ll be at a loss.

The iOS community still speaks in Objective C.

Just have a quick browse through iOS development questions tagged on Stack Overflow, and you’ll realise something — most questions are asked, or answered using Objective C and not Swift. If you want to integrate into a community, you have to speak its language. Even if you do manage to find something that solves your problem that is answered in Swift, it is still good to be able to understand other answers written in Objective C and assess for yourself which gets the job done more effectively.

The majority of tutorials and documentation available on the internet, as well as programming books in print, are all still written in Objective C. If you’re a beginner, it’s much better to have a multitude of resources at your fingertips rather than have to hunt for an answer to your question that you can understand. Furthermore, these resources are tried and tested, given that Objective C has been around for nearly 25 years. The community has pretty much established the best design patterns and practices for development.

What if you’re not a beginner but an established application developer who’s making the jump to iOS development? Most companies which have invested several years and thousands of dollars into maintaining their apps are probably not about to rewrite their apps in Swift any time soon. And even if they are, knowledge of Objective C is most likely going to be considered a bonus, if not a requirement, when you look for jobs.

Why not use both?

Apple has made a good choice in making Swift compatible with Objective C. What this means is that both codes and can run side by side in the same project, which is great.

But what does this mean for you, as a developer? It means that you have the option of learning with Objective C, with plenty of resources in your hands, make a few apps and become proficient at using the Apple frameworks. And then once you’re comfortable, you can move on to Swift (which should be really simple to learn once you’re familiar with Objective C) and start experimenting with the future of iOS development.