Site icon Treehouse Blog

Should You Learn Swift or Objective-C? The Short Answer is Both.

In 2014, Apple released a brand new programming language, Swift, that took the community quite by surprise. In the two years since, the Swift core team has iterated rapidly, releasing several major and minor versions of the language much to the community’s delight and dismay.

While Swift has interesting implications for existing developers, it has introduced a bit of complexity for newcomers looking to learn iOS development.

So, which language should you learn – Swift or Objective-C?

If you’re looking for a short answer, it’s both. To understand why exactly, let’s talk about the merits of learning each language on its own. Most of the posts out there that touch on this topic approach it from the standpoint of an existing developer and tout features like “lack of pointers” and “type safety”, none of which matter to beginners.

[Tweet “Should I learn Swift or Objective-C?”]

Why Should I Learn Swift?

For understanding the basics of programming, Swift is a much easier language to work with. Objective-C is over 30 years old and was written at a time when different considerations had to be made regarding how we interacted with computers. These considerations, while important to know and understand even today, can make learning the basics of programming daunting.

So point #1, the basics of programming are easier to understand with Swift than with Objective-C. Key word here is basics.

Interactive Environments

Along with Swift, Apple released two rich, interactive coding environments that help beginners learn how to code. There’s Xcode Playgrounds, which is an environment that’s part of a Mac app called Xcode and allows you “to learn and explore Swift, prototype parts of your app, and create learning environments for others.”

There’s also an iPad app called Swift Playgrounds (releasing with iOS 10 in Fall 2016) that provides the same interactive environment as Xcode Playgrounds, but in a much more exploratory fashion that allows you to use your iPad’s hardware as well.

This brings us to point #2 –  the environment for learning Swift is far more engaging and provides immediate feedback, making concepts easier to learn. This type of environment isn’t unique to Swift, but Apple’s doing some cool things, particularly with the iPad app, that makes learning for absolute beginners fun. In our experience teaching at Treehouse, Xcode Playgrounds have reduced the barrier to entry by allowing students to jump right in. The fun part is important too; no one likes learning when it’s boring.

Safe

When Apple released Swift they claimed it was three things: safe, modern and powerful. While modernity and power of a programming language mean little to an absolute beginner, safety is particularly important.

When learning how to program, one of the hardest things is not knowing what went wrong. Of course, there is immense benefit from figuring that out yourself and learning from it, but often times, the lack of proper feedback (from a beginner’s perspective) can put some off. By being safer, Swift can prevent a whole category of mistakes or errors from arising and inform us iteratively of what we’re doing wrong.

Point #3, Swift is safer and this will benefit you by making your code writing experience less frustrating.

Modern

One of the modern aspects of Swift is that it is easier to read and write than Objective-C. Across the internet, you will see it written that this doesn’t matter because everything is easier to understand once you’ve had sufficient experience with it. That point of view ignores a newcomer’s perspective (it’s like saying it’s easier to read/write German once you know German).

It’s hard enough to figure out concepts already without getting tripped up reading code. You also won’t have your programs crash because you forgot a semi colon at the end of the line. Again, these are minor things once you get used to it, but they certainly are advantages that Swift brings to the table for beginners.

Point #4, Swift is modern and this will lower the barrier to entry for many people, making it easier to focus on concepts than on extraneous syntax.

So to summarize, learning and understanding the basics of programming, which is the first step in your journey to learn iPhone development is easier in Swift. The richer coding environments (compared to Objective-C), the modernity and safety provided by the languages all contribute to lowering the barrier to entry.

Why Should I Learn Objective-C?

This answer will change as the years go by and Swift makes more in-roads in the community, but for now, there’s just one thing to know about Objective-C: it’s been the de facto language for iOS development for around 10 years. In addition, if you’re looking to become a MacOS developer, Objective-C has been the language of choice since the late 80s.

This means that everything in the iOS SDK has been built in Objective-C and works best with the Objective-C programming model in mind. Even if you’re writing code in Swift, you’re going to be interacting with components all written in Objective-C.

Since Objective-C has been around much longer, third party libraries and frameworks (code written by other people/teams that you can use) are primarily in Objective-C as well.

Furthermore, the overwhelming majority of learning resources – books, blog posts, conference videos and so on, are all in Objective-C, so if you turn to the internet for help for some arcane issue, chances are you’ll be reading Objective-C code. Now this is rapidly changing mind you. The Swift community is an eager one and there’s plenty of resources in Swift so don’t feel like you’ll have a hard time looking for help.

Point #1. The bottom line is though, if you intend to be a serious iOS developer, you’ll need to know how to read and write Objective-C code as well. Perhaps the most important reason of all, is that if you get a job as an iOS developer or inherit an older project, all the code will be written in Objective-C and you will be expected to know how to work with it.

Point #2. The tools we use for iOS development aren’t optimized for Swift yet. It’s getting there, but it’s far better with Objective-C and because tooling is important to getting your job done, Objective-C still remains the development language of choice for most companies.

Why Should I Learn Both?

Apple didn’t release a brand new language just for the fun of it. The release of Swift, the rapid iteration by the core team and the effort at increasing adoption in the community all provide a clear indication that Apple sees Swift as the future of its platforms.

Apple’s goals for Swift extend beyond iOS development as well, with work well underway for server side Swift and usage in embedded systems.

If you plan on being a part of this community for the long run, then Swift will (at some point) become your primary development language. The only thing that’s up in the air is how long that is going to take.

Despite Swift’s rapid adoption, Objective-C isn’t going anywhere anytime soon. Apple is still making incremental improvements to the language, particularly in how it inter-operates with Swift, so for now it looks like the intention is for us to work with the language that’s best for the task at hand.

It’s possible to write apps entirely in Swift but there’s a pretty high chance you’ll need to dip into Objective-C once in a while.

You should be aware, if you’re coming to this as a beginner, that the hard part of iOS development isn’t the language. Once you know one programming language, learning another isn’t all that difficult. Sometimes you need to use a different mental model, but it’s not like starting from scratch.

What is difficult though is using the vast iOS SDK to build apps. The language is just one of the tools you use to do this.

If you plan on being a part of this community for the long run, then Swift will (at some point) become your primary development language. The only thing that’s up in the air is how long that is going to take.

How Should I Approach the Task?

Now this is purely my take on the matter but I recommend a Swift first approach for both absolute beginners or those from different development domains. You can get comfortable with programming concepts and the basics of iOS development without letting the language get in your way.

Once you have the basics down, you should switch gears and work on a few projects in Objective-C. You’ll be introduced to important concepts that lift the hood on how some things work “automatically” in Swift and give you a deeper understanding of programming.

You’ll also learn more about why the iOS SDK is built the way it is, and how some of those choices, while out of place in Swift, lend itself to powerful flexibility in Objective-C.

Once you’ve spent enough time with both languages, you’ll have a much broader understanding of iOS development as a whole and be able to move seamlessly between the two.

Coincidentally this is how we teach at Treehouse. 🙂

Now there’s one further complication that needs to be addressed at the time of this writing. If you’re looking to learn Swift right now (July 2016), should you learn Swift 2.3 or wait until Swift 3 is out?

I say start immediately. The transition from Swift 2 to Swift 3 will not be so jarring for those just starting out. It’s more cumbersome for those of us who already have code in Swift 2 and need to bring it up to speed.

At Treehouse, once Swift 3 is out, for those of you who already know Swift 2, there will be a series of workshops that inform you of the changes you need to make to your code. For those that are just starting out, we’ll introduce brand new content that teaches using Swift 3.

[Tweet “Should I learn Swift or Objective-C? by @pasanpr via @treehouse_blog”]


Start your new career as an iOS Developer, who typically earns a starting salary of $70k per year.
Exit mobile version