Swift vs. Objective-C: The trending up-and-comer vs. the dinosaur

Well, one big advantage is adaptability at runtime.

This means accessing private APIs or doing things like mocking objects at runtime become possible.

This can be especially useful when it comes to unit testing.

Libraries like OCMock make this even easier and allow for very elaborate test set ups.

Having good unit tests will make your app more stable and reliable.

Speaking of stability, Objective-C has been around for a long time which makes it a very stable language.

With Swift, you’ll run into bugs that are pretty surprising and would be disruptive to the stability of your app.

In the example I linked above, this crash would be caused by the actual language you are using to code your app, not due to any error created by the code you wrote.

This can be frustrating.

The last point, which is more important to certain companies, is compatibility with C and C++ libraries.

Being that Objective-C is a superset of C, it is easy to use C and C++ code with Objective-C.

You can even use Objective-C++ if you feel so inclined.

This is important if your are dependent on third party C and C++ libraries.

The weaknessesThe first main complaint I hear about Objective-C is syntax.

I started my professional career using Objective-C so I have no issues with it.

It is verbose and a bit unconventional with the use of square brackets.

But opinions on syntax are just that, opinions.

I figured I would list this point though since it is one of the first things that comes up when you mention Objective-C.

One thing I do agree with though is that block syntax is frustrating.

There is even a website dedicated to decoding the mysteries of blocks in Objective-C.

I actually use this website pretty often as a reference.

Objective-C can be a bit verbose.

Check out this Github page for even better examples.

The biggest issue Objective-C faces right now is the fact that one day Apple may drop support for Objective-C with Cocoa and other common libraries used to create iOS apps.

Since Objective-C is primarily used to create iOS apps, this would be a death knell for the language.

It also means that newcomers to the iOS community are afraid to commit to learning Objective-C right now since it may no longer be used in the future.

Let’s get back to the language itself.

It is prone to having hard to debug issues due to the dynamic nature of the language.

The ability to send messages to nil and not crash on top of the lack of strict typing are some examples of things that lead to these hard to debug issues.

Objective-C does not hold your hand when it comes to these things either.

Though it is nice that the app doesn’t crash when you send a message to nil, it may put your app in a weird state.

It is very hard to debug issues like these.

The fact that Swift has strict typing and the use of unwrapping optionals prevents these things at compile time.

Should I learn Swift or Objective-C?The answer for most people will be Swift.

Apple is clearly pushing Swift as the language of choice for its iOS application development community.

Swift will only continue to become more performant as ABI stability is introduced and Swift becomes packaged with the OS itself.

If you’re looking to get a job as an iOS developer, Swift will be the language you want to learn.

Most startup to mid-level companies will have their iOS apps written completely in Swift.

This means you’ll be able to apply and interview for more jobs if you learn Swift.

Even at larger companies where Objective-C is still used heavily, interviews can still be done in Swift.

So you can learn Objective-C once you join the company and not worry about burdening yourself with more things to learn before the interview.

You will want to learn Objective-C if you are already working at a start up or mid-level company and want to jump to a larger company.

Skills with Objective-C will give you specialized knowledge and an edge over other interview candidates.

Liked what you read?.Take a look at some of my other articles:Tips for your first tech interview.

Starting a tech career from nothing.

Should you get a computer science degree?.

. More details

Leave a Reply