Should You Learn Swift Or Objective-C

Should You Learn Swift Or Objective-C

The most common question asked by developers new to Cocoa development is about the language they should learn, Swift or Objective-C. The question is simple. The answer is not.

As far as Apple is concerned, Swift is the future. But Apple isn't oblivious to the fact that hundreds of thousands of applications and thousands of open source libraries are written in C and Objective-C. The company very well knows that Objective-C will be around for many, many years to come.

A few months ago, Ryan Olson scoured the App Store to find out how many applications are already taking advantage of Swift. His investigation revealed that a little over 10% of the top 100 free applications contained some Swift.

After discovering that only a fraction of the most popular iOS applications has adopted Swift to some extent, Ryan wondered how much the company behind the language had invested in Swift. Apple's Calculator application, for example, is mostly powered by Swift. With less than 3% of its classes written in Swift, the WWDC application is primarily built on C and Objective-C.

These findings make you wonder how confident the company is about the current state of the language. And what does that mean for developers?

Objective-C Is Everywhere

Objective-C has been around for more than three decades. The vast majority of native iOS and macOS applications is powered by the language. No matter how fiercely Apple promotes Swift, Objective-C will be around for a few more years.

Most developers making a living developing iOS and macOS applications continue to use Objective-C for most of their work. Swift is the new kid on the block, but it's still a kid. If you want to get work done, Objective-C is the way to go.

Swift is the new kid on the block, but it's still a kid. If you want to get work done, Objective-C is the way to go.

At the time of writing, Apple's software development kits are primarily written in C and Objective-C. This isn't a problem for Swift development, though. Apple made sure Swift and Objective-C play along nicely. In fact, this is instrumental to make a gradual and controlled transition possible.

Important concepts, such as pointers, object references, and automatic memory management, are easily overlooked if Objective-C is ignored. Remember that Swift uses the Objective-C runtime under the hood.

Swift Is Everywhere

Swift is heavily promoted by Apple and the language is quickly gaining traction. Swift 3 was officially released a few days ago and Xcode 8, which was released earlier this month, makes working with Swift faster and easier.

I use Swift for every side project I create and most people that teach iOS and macOS development focus exclusively on Swift. It is clear that Swift is the future and, from the looks of it, that isn't going to change.

With Swift being open source, the language is spreading beyond the borders of iOS and macOS. Learning Swift may become a skill that pays dividends in the—not so distant—future, and not only if you focus on iOS and macOS development.

What Language Should You Learn?

What does that mean for aspiring Cocoa developers? My advice is simple. Learn both languages. But start with Swift.

Learn both languages. But start with Swift.

The addition of playgrounds in Xcode, and more recently on iPad, has made it easy and fun to learn the ropes of Swift development. It is no longer necessary to learn the ins and outs of Xcode just to get started. Apple knows that it needs to make the barrier to entry as low as possible. Swift development should be easy, fun, and enjoyable.

Once you understand the basics of Swift, spend some time with Objective-C. It will make you more confident as an iOS and macOS developer. And it will help you understand memory management concepts that are essential to build reliable, robust applications.

If your ambition is to build Cocoa applications for a living, C and Objective-C are even more important. Companies specializing in native iOS and macOS development continue to rely heavily on C and Objective-C. Existing projects need to be maintained and porting hundreds of thousands of lines of code from Objective-C to Swift is not an option in most scenarios.

Swift is the future. Objective-C is the present ... for now.