Don’t mind to use Objective-C

Since the first Swift release in 2014, It seems like Swift is a super rock star which takes over the stage. As advertising, Swift is more modern, elegant and even faster. Well, they talk it up a lot. More and more companies have decided to migrate to Swift. Many many senior developers have moved away from Objective-C. Fresh iOS developers are told to learn Swift rather than Objective-C.

However, Objective-C won’t be dying. It will last long for many reasons. Let’s go through the following reasons which I recap below

Objective-C will last long

Legacy projects

Youtube is the one which has been written in Objective-C for several years. In a few months ago, I looked over it its IPA package and tried to reverse engineer it. It is still in Objective-C. I guess it not going to Swift anytime soon.

Recently, I have had some chats with some guys from top tech companies like Facebook, Snapchat, and some other ones. They’re still looking for iOS developers who have main skills on Objective-C rather than Swift. Because the fact is their many-year-old projects are written in Objective-C. Their projects are better going with Objective-C for some reasons or basically, they have no plan to move to Swift.

The simplest thing I can understand and reasonable to bring out is Migration is not a simple task. It can’t be done in a few days, weeks for many reasons:

  • Some kinds of logic in Objective-C need to be written in different ways in Swift because the similar APIs are not available, and some concepts in Objective-C not working for Swift. Some cases, the implementation needs to change to take advantages of Swift. If not, you’re not using Swift.
  •  Some cases, unfortunately, the author who wrote the original code, left the company. The person who made the calls on some certain business flow, he left. These leave several dark holes in the project.
  • Hidden risks, timeline, goals, benefits, costs, humans, are things which a company needs to consider. Swift is worthy?

If I were a leader, I would not want to halt the current project, go back the start point and rework everything which is accumulated in many years.

The last time, I have talked with an Apple guy about if Apple will abandon Objective-C in the future? Well, the answer is even Apple, it has many projects in Objective-C for many years past. They are many years old and not able to be replaced anytime soon.

Lower maintenance cost, more reliable

Why writing code in Objective-C is more reliable and spend less on maintenance cost. Well, I conclude this depending on something I experience

The evolution of Swift happens so quickly. Because of something. One, Swift is backed by Apple. Two, it is open source, anyone on the world can propose any changes to make it better. Both two of these are good but it also is a tradeoff.

Swift 1, Swift 2, Swift 3, Swift 4, Swift 4.2. Most of them are not backward compatible.

Projects in Swift 1 must migrate to Swift 2, and one year later migrate to the next Swift version, next year keep doing it over. The changes can be various. The change can be on Syntax, can be on organizing structure, code refactoring, class, type, and enum renaming, APIs removed, any reasons. However, Objective-C remains consistent over decades

Are you a fan of open source? Well, I am. I have studied many many open source project from Github. If you’re as same as me, I’m sure You may not have a smooth experience with Swift. If checking out the projects in Swift which were created before 2018, most of them are all broken because of the changes of Swift. Well, You may have to spend hours to migrate them into the latest Swift version, and after that, you might not expect it work properly as same as the original one. Some cases, it doesn’t only take your time to fix the compile issue, but it requires you to have some knowledge on certain domains to fix that. The open source usually not come along with Unit Tests, so the reliability is zero.

Conversely, Objective-C projects are fine, long-lived. I have checked out some Objective-C projects which were written since around 5 years ago, they’re still ok.
Check out, compile and run instantly, no error at all. I believe that the code which I run work as same as what it’s supposed to be, in term of the author’s idea. The reliable here is 100%.

The labor cost in the US isn’t cheap. The average salary of a programmer in the States is approximately 120 grand per year, so each working hour is not less than 100 bucks. Who pays for maintenance cost? In this area, I highly recommend Objective-C over Swift. The companies which truly count on technologies and make business on technologies, they have developed many many homegrown projects, apps, frameworks, tools.

Swift is young, it is growing up over years. Therefore, There will more change coming

Manual memory management support

The fresh iOS developers nowadays may not know about the retain count concept. They might not care much about memory management in iOS and they do not easily have a chance to have that experience.

iOS devices nowadays are more powerful, stronger, RAM capacity is even up to 3GB and more in the future (It is a few times stronger than my family PC with Intel Pentium 2 Celeron, 64Mb RAM), so Apple seems like not encourage us to deal with the issue like memory management. The branch new project is created will be set to Automatic Reference Counting mode by default.

manual memory management
Turn off automatic reference counting

However, For some reasons, You must manually manage memory in your project, you can still go for it.

Open up the Project Settings, then go Build Settings and turn off Automatic Reference Counting (or ARC).

manual gear.png
Many people still use manual gear car, nowadays. Don’t you?

Coexist with Swift

Swift and Objective-C are two distinct programming languages, but they are able to call each other with minimal configuration. (Learn more about Import Swift into Objective-C, import Objective-C into Swift)

import swift

This is so much flexible for everyone. You don’t have to rewrite everything in Swift or Objective-C, and you have a choice to develop a hybrid app in both Swift, Objective-C

Language Characteristic

Although Swift remains some as same concepts as Objective-C, Objective-C still has many extinct characters which Swift doesn’t have. These are reasons not everyone wants to move away from Objective-C.

  • Interface and Implementation separation
    Unlike Swift, Objective-C keeps the public interface in a header file, the private interface, API, and implementation is kept in an implementation file. Most people still admire this feature. Swift mixes up everything in one file, this may not an advantage some cases.
  • Object Association
    This feature does not work in Swift but works in Objective-C. Well, this is a must-have thing. Especially helpful, when adding an additional property to a class category.
  • Property attributes
    In Objective-C, you have more many options to set additional attributes to a property. For example atomic, nonatomic, assign, weak, strong, retain, read-only, getter, setter.
  • Unique APIs available
    Some methods just are available in Objective-C. For example dispatch_once(…). Some of them can be reimplemented easily in Swift, but in some cases, you can’t.

Mix mode

In Objective-C, you can write C++, C, Objective-C, and even Assembly interchangeably. Objective-C can call C++, C directly and vice versa.

You can have an Objective-C object which wraps around a C++ object or C APIs. There are some reasons for these in practice. C and C++ can be compiled for across platforms. Many C or C++ libraries were uniquely developed a long time ago. They were proven, trusted, reliable for decades, anyway, We don’t want to reinvent the wheel.

In some use cases, You can have C functions to call Objective-C methods. C++ object can wrap around Objective-C. There are some reasons for applying this. Your C / C++ program want to call the iOS specific API because this is the only way the C / C++ program can do to interact with native API.
For example, if a C / C++ program wants to send a notification, you may have to write a function which invokes NSNotificationCenter and fire the event in Objective-C. C/C++ program here can be a Unity game, a Cocoa2dx game or a Xamarin program.

Pointer & Low API friendly

If you’re going to develop the program which especially works with the pointer, then I think Objective-C is a better language to work with.

Working with some low API, some engines like OpenGL, Objective-C is a better choice. Swift can do the same do, but you will struggle to find the way out. Write a program with involving OpenGL, build the shader, setup buffer, pass the parameters in and out shader program, everything in Objective-C is not easy but easier than Swift.

Sometimes I cannot find a way to write the same thing in Swift to call a low API, so I don’t think Swift is friendly in this area.

Last word

In my opinion, Programming language is not a technology, it is a language for human. The most important thing to a programming language is how it helps express your idea in order to make up a program. There are hundreds programming languages, each one comes up with its own style and concepts. There is no one best.

If you fall in love with Objective-C, then go for it. Don’t be mind. I gave you a few in thousand reasons

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s