Objective-C Is Dead, Why and How To Build Mobile Apps in Swift.

Even though there is a plenty of Objective-C out there, if you’re not writing Swift now, you’re way behind as a software engineer and as an engineering organization. This blog post goes over challenges behind using the Swift programming language at a legacy project and how to overcome them.

Why Swift

  • At this point, Swift is becoming mainstream for iOS app development. It reached a stable place and the API doesn’t change much. There is a plenty of Swift packages.
  • More and more command line tools are written in Swift outside of mobile app development.
  • Swift is picking up momentum on the server-side. There are several server-side swift frameworks available already and Apple is now really pushing for server-side Swift.
  • Swift is a better language than Objective-C and this awesome post explains pretty well why. It’s faster, safer, more expressive, and more fun to work with.
  • Knowing Swift becomes a requirement for a mobile app developer. If it’s not a requirement for the job you’re applying for, you probably don’t want to work there anyway.

I know that you may be using Objective-C and you became very efficient at it. It’s time for a change, so be a developer athlete and let it go.

Let it go

Starting a new project in Swift

Back in August 2014, when I was running the engineering team at AwesomenessTV, I wouldn’t start a new project in Swift. We decided to start a project in Objective-C and migrate to Swift overtime. Here is a quick presentation from the LA Swift Meetup explaining the reasoning behind it:

Fast forward a couple of years and my decision would be completely opposite. If you’re starting a new project now, don’t hesitate and choose the Swift language.

Migrating an existing Objective-C project to Swift

Since Objective-C has been around for almost 20 years, there is a lot of useful code written. Chances are that your existing project is either written in Objective-C entirely or most of the project is written in Objective-C. No worries, here are the steps to migrate it to Swift seamlessly:

Commit to the Swift migration as a team

Hopefully, you’re on the team with like-minded innovative app developers. If not, there is some work that needs to be done. Depending on your team, you may hold a team meeting where you bring your Swift migration proposal. Come prepared with a detailed plan (we’ll go over that in a bit). If you follow the Agile Methodology, the best place to bring it up is a retrospective meeting. If you have some old school developers on the team, have a casual conversation with each of them separately. Tell them about your plan and ask them for their opinion. They will feel invested in the outcome. A great book on the topic is Switch: How to Change Things When Change Is Hard.

Start writing tests and new code in Swift

Migrating the entire Objective-C codebase to Swift in one shot doesn’t make sense. The benefit of re-writing things in Swift is to improve your code and to make a solid foundation for future changes. If there is some solid Objective-C code in the app that works well and you don’t have to modify it, it doesn’t make sense to re-write it. Focus on new code. The two obvious candidates are your new tests and new code files. Set up your Objective-C bridging header, start writing new files and in Swift and just reuse the existing Objective-C code. Create Swift Extensions for an already existing Objective-C class if it makes sense.

If you’re modifying an Objective-C file, convert it to Swift

If your files are small in size, converting an Objective-C file to Swift may be a straightforward talk as you’re in it. I do it pretty frequently and it’s a great way to make progress on the Swift migration without sacrificing feature velocity.

Final words

It’s the best time to be an iOS mobile app developer. Swift is a fantastic programming language and the mobile app industry is a great place to be in. There are new exciting mobile apps built every day. In order to make this world better, we need a better language. So leave the legacy behind and innovate!