Select Page

With the backing of a growing community of developers, Swift has quickly become popular by being streamlined and open source. On Swift.org, developers have taken a shine to continually improving this language, and Apple has responded in kind with frequent updates. It is the sort of mutual communication that proves beneficial to the development community.

However, with this level of change, iOS developers have had to contend with updating existing applications from Objective-C to Swift. Despite both being Apple programming languages and a high degree of interoperability, anyone hoping to transition to Swift will have to evaluate their programs and determine what reason they have to use it.

Amy Dyer, a software engineer at Etsy, recently released an excellent talk on the ins and outs of the upgrade process, and I highly recommend giving it a look. But, if you don’t have the time to watch the whole video, I’d like to talk a little about what works and what doesn’t when it comes to implementing Swift.

So let’s say you’ve heard about Swift. Maybe another iOS developer has raved about how much simpler and less buggy it is. Hey, maybe you’ve even toyed around with it. But most of what you’ve built has been in Objective-C, and you’re hesitant to move to Swift when your code has been largely functional.

And maybe you personally have a good reason to stay, though I’ve been a huge fan of Swift’s innovation since day one. That said, there are a few areas in which Objective-C is lacking that Swift can help you with, and figuring these out is the key to reevaluating your code.

Optionals

This is one of the biggest differences. The ability to return nil with a function that references type is something that does not exist in Objective-C, and making this kind of mistake does not raise any errors, potentially leading to bugs later on.

Type Inference

Speaking of type processing, Swift is smart enough to assign variables typing based on their given values. It’s a simple change, but makes code smaller by reducing the number of necessary lines.

Strings

Modifying strings has also become far easier. Swift eliminates the need to create a new string object out of multiple strings using “stringWithFormat,” now, basic addition operators will do the trick nicely.

Guard

Avoid function creep with guard, a conditional statement that stops flow if a condition is not met, allowing for easy combination of if/else statements.

The Times, They Are A Changin’

So you get the idea. These are just some of the ways that Swift improves on Objective-C’s functionality. This should give you a basic sense of some of the reasons to make the transition. But what else needs to be considered?

The brilliant part about the two languages is that a complete overhaul is not necessary. With the high level of interoperability, gradually grafting Swift into your code is a very realistic goal. Of course, there are risks involved, the most salient of which is perhaps the simple fact that Swift is still undergoing numerous updates, a few of which have been problematic for existing apps.

One of Dyer’s solutions to moving forward is to write code that can be created in both Objective-C and Swift. Of course, this raises numerous backward compatibility issues, which she dealt with by using access levels to flag any code exclusive to Swift.

There’s even a macro to change the way Swift interprets functions, allowing for the language to process previously problematic sections of Objective-C code.

Regardless of how you choose to adopt Swift, the big issue is inevitably consistency, whether in the ways we just described or among different Swift developers, particularly if they’re working in the same office.

The good news is that there will always be similarly inquisitive individuals to assist with any issues you’re having with the process. Apple is attempting to draw skilled developers to Swift, and making it open source is the proverbial carrot that has allowed the language to gain so much attention. So, whether you’re new to iOS development or looking to make the jump from Objective-C, always be cognizant of what you’re looking to gain from Swift adoption.

I’ve been working with Swift since it was announced in 2014, writing an app in the language when it was only at version 1.2. I’ve watched Swift evolve for the last couple of years, and am excited about how far it has come in a relatively short time. Swift 3.0 is a major turning point for the language, and I’m excited to see developers continue to adopt it.