Swift vs Objective C: the winner is....

Swift vs Objective C: the winner is....

Since the announcement of the Swift programming language a year ago there's an unprecedented buzz in the iOS community for Swift. Swift has become the most desired programming language to work with according to the largest developer survey in 2015 conducted by StackOverflow. On WWDC Apple announced it will open source Swift to support OSX and Linux, further adding to the anticipation. And on this years Apple developer conference, almost all of the demos and codes have been written using Swift.

Still (Very) Few Swift iOS Apps

Yet, despite all the buzz, Swift is not taking off as the language to build - at least not when building apps that are published on the App Store. Lyft, the rideshare service were one of the few notable companies to announce they have released an app written 100% using Swift. Most companies however are taking a "Wait and see" approach, monitoring the new language and running experiments, but holding off shipping anything built on Swift - yet.

And there are plenty of valid reasons not wanting to adopt Swift, despite it being the better in almost every way to Objective C. Andecdotally, every time Apple releases a new Swift update, it takes a couple of days to migrate existing code. XCode 7 - which supports Swift 2.0 - is still in beta and crashes frequently when developing. And let's not forget what happened with Python: v2 of the language still has 68% of usage among developers  - that is 6 years after the new and better v3 version has been released. These all show that uptake of a new and language - however improved it might be - is not trivial.

Using Both Instead Just One: Mixed Applications

It is clear that Apple is serious about Swift being the future of iOS and OSX development. What is not clear is when it makes sense to switch over to Swift - and we can expect Apple to give the little and vague guidance they have, leaving it up to engineers to decide how and when to go about it.

There is lots of debate on using Swift or Objective C for app development. But many people forget that it doesn't have to be one or the other: Swift and Objective C can be used together, in the same project or app. This approach - using Swift and Objecive C together - is mentioned in the Apple documentation, but not explained in much detail.

This is the exact approach I'm taking when building production apps at Skyscanner: writing the majority of the code in Objective C, but introducing Swift classes and components one by one. The app itself will likely never be 100% Swift, but over time I expect Swift to make up the majority of the production code - as well as the automated tests.

I've created a Github repository to make getting started with Swift and Objective C mixed language applications easier. For production level applications there are a few gotchas, such as using mixed language tests which are also documented in the repository.

So the winner is...

... definitely Swift - but only over time, and there won't be a definite "switch date". I am on the same opinion as Benjamin Sandofsky who says Objective C won't be deprecated, but it will slowly and continuously fade away, or as he puts it "Objective C will move to Florida to enjoy its golden years (...) and its nights sipping margaritas with the OAuth library everyone fears rewriting."

What is certain that it is time for iOS engineers to ramp up learning Swift. The least risk free way of doing so is by introducing Swift to your existing Objective C applications - one class at a time.

For a more detailed guide on getting started with this, see this short guide and example code on getting started with mixed Swift and Objective C projects.

要查看或添加评论,请登录

Gergely Orosz的更多文章

社区洞察

其他会员也浏览了