When I first signed up to be an Apple Developer two years ago there was only one language that you could use to develop iOS apps – Objective-C.
In 2014 that changed when Apple introduced Swift. Swift was probably not a wise choice for production code until at least the 2.0 release in 2015 as it was still changing quite a lot, but it has become more stable and mature, and many people are now using it as their main production language.
I started building my first app Decks in early 2014 so I used Objective-C. When Swift was first released I questioned whether I should change over to it straight away as I hadn’t yet released the app, but due to other commitments I ended up not working on iOS development at all for a full year!
This year I’ve picked up my iOS development and have shipped version 1.0 of Decks. I continued to develop Decks in Objective-C because a lot of it was already written and it seemed the wisest thing to do. But I have been learning Swift programming as well.
So when I recently started building my second app, I was unsure which way to go. I already had a lot of Objective-C code I’d worked out for Decks and felt it might be easier to re-use that code and continue building in Objective-C for the time being, but I was also aware that Swift is very much the future. Apple is pushing Swift and it seems sensible to get your head around it as soon as you can.
If this is a hard choice for me having just scrabbled together my first Objective-C app then I can’t imagine how hard it is for developers who have many years of experience and thousands of lines of working tested Objective-C code already written.
Another problem I found was that the support community around Objective-C is far more mature and comprehensive. If you come up against a problem and do a search you’ll find much more help on Google and Stack Overflow for your Objective-C problems than your Swift problems.
A quick check just now on Stack Overflow returned 236,404 questions tagged with “Objective-C” and only 47,747 tagged with “Swift”. It’s amazing how much Swift support there is already but there is understandably a longer and wider history with Objective-C.
This is also the case with libraries. The vast majority of mature, well-supported, third-party libraries are in Objective-C. Again, a quick search on CocoaPods revealed 10,161 Objective-C libraries against 1,054 written in Swift.
These differences are lessening day by day and more community support and libraries for Swift are appearing at a fast rate. In another couple of years Swift will no doubt catch up with Objective-C completely in these regards but in my short learning experience it definitely makes it harder to work in Swift at the moment if you’re a beginner. I have found the support available on Stack Overflow particularly useful.
You can of course use Objective-C within your Swift projects using Apple’s bridging header which allows you to take advantage of Objective-C libraries but then it would still be wise to have some understanding of the Objective-C code in case you need to debug or edit it.
I decided to do a quick experiment and started two versions of the new app, one in Objective-C and one in Swift to just see how different the experience was for me with the knowledge I currently have. So far I have managed to achieve the same in both but it has taken slightly more time and work to develop in Swift and I have also had to use a bridging header to add in an Objective-C library that I couldn’t find an equivalent of in Swift.
I’m not saying that this will be the case for everyone as I am a beginner and I still need a lot of hand-holding to solve problems that more experienced programmers wouldn’t have to deal with, but for me Swift is slightly slower and harder to develop with. This seems strange in some ways as the Swift language itself is less verbose and easier to read and understand, but there is so much useful Objective-C code out there that you can cut and paste and adapt to your needs.
My experiment is still at an early stage and I’ll continue it a while longer before deciding which way to go. Ultimately, I know I’ll have to go with Swift on all new projects, it just makes more sense in the long run.
But my advice to a new developer starting out today on iOS is to learn both languages. You really need to be familiar with Objective-C and Swift at this moment in time.