Sep 25, 2020, Mobile

What’s the fuss about the “Swift vs Objective-c” thing?

iteo team

You can find a lot of articles about comparing Swift to Objective-C. When it comes to choosing language for the new project there is no doubt that Swift will be a better choice. But we have to understand why. 

Objective-C language is around for a really long time. It was first introduced in 1984 – the same year that Apple presented its Macintosh 128K with the famous Super Bowl ad (the number stands for its built-in RAM – blazing 128kb). It’s not difficult to count that it is getting close to 40 years old. When you see it this way, you can understand that Apple built its whole ecosystem on this language. Everything we use now was initially written in Objective-C. Even now Apple is still releasing new features including Objective-C implementations in developer documentations. It is a grown, adult, respected, and well developed language.

Objective-C – pros and cons

Although a newly released language like Swift was designed to conquer all the weaknesses of its antecedent, Objective-C still has some advantages. First of all, it is interoperable with C and C++. Also, it supports binary frameworks development and offers dynamic features – for example method swizzling. Not to mention, a language that is around for more than 30 years was thoroughly tested on thousands of code lines and applications.

When it comes to cons, the main problem with Objective-C is the fact that its structure is quite complicated. It requires explicit pointers, the knowledge of prefixes and understanding of its complex syntax. We need to remember that it is old, so reverse engineering and hacking is much easier, too.

As you can see, despite its age, Objective-C can still be used for some purposes but it can be harder to learn, especially for new developers that didn’t have a lot to do with old-fashioned languages. Swift has something more to offer and it is picked as primary technology used to code for Apple devices. Why?

Swift – pros and cons

Apple’s goal with creating Swift was not only to fix some issues that Objective-C couldn’t overcome. With rapidly growing technological advancement, all hardware and dedicated apps started to become more sophisticated. They needed a programming language that would cope with all the requirements and would allow developers to code faster.

Swift is compatible with Objective-C and Apple development frameworks called Cocoa and Cocoa Touch. The app’s code can be a mix of two languages and also migrating from one language to another is not problematic.

What are the main benefits of Swift?

  1. Swift is definitely faster when it comes to coding and performance. It also offers more stability.
  2. It is easier to learn and use for programmers – especially ones that knew Java, JavaScript, Python, C#, or C++ before. Its syntax is quite concise and doesn’t require as much code to achieve excellent results.
  3. Overall, Swift code is easier to maintain and more productive to write. It is considered safer as it doesn’t use pointers. They are often responsible for security vulnerabilities and constrict finding bugs.
  4. With SwiftUI, a dedicated framework, building accessible and multi-platform interfaces is easy.
  5. Swift is one of the leading programming languages in the IT community and has enormous support from hundreds of devs.
  6. There are many development tools like Playgrounds that make the app production process more efficient.

Disadvantages of Swift

Changing versions of the language sometimes can become problematic, as they can eat up a significant part of the developer’s time. This problem though is shrinking as Swift matures and doesn’t require so many updates.

Speaking of age, as a young programming language, Swift still requires some fixes and upgrades. Migrating software between two versions of Swift is oftentimes complicated, especially with advanced apps that have lots of code.

It is obvious that there is no perfect technology without flaws. The question is – when to pick Swift and when you should trust Objective-C?

So – which to choose?

And here we are, reading what to choose. The answer is quite clear – choose Swift.  If you’re dealing with a new project, or even have an old one that still works pretty well, I encourage you to migrate to Swift. It is developer friendly and fast, and it gives you decent flexibility. It lets the developer focus on his tasks being clear and readable, with many unnecessary syntax elements stripped of. Swift has been with us since 2014 and it is open-source. It had gone through some major changes and a lot of tweaking. Right now, it is safe to say that it has entered adulthood in its development. In 2019 it implemented ABI stability for all Apple platforms – it means that since Swift 5 version, all custom libraries will be compatible with future versions of Swift. It was a big milestone and now, when developing an app in Swift, you can no longer fear that a new major release will bring breaking changes.

When comparing Swift and Objective-C with regard to general overhaul of the languages, Objective-C doesn’t really deserve much credit these days. Why? Because we can achieve almost everything using Swift. You can, with no trouble at all, include code in C or C++. There are some solutions that Objective-C gives out of box but some of them are considered a bad practice – mainly for security and code encapsulation reasons. Furthermore, you can make Swift projects look exactly like Objective-C in case of code and files structure but it would be somewhat impossible to do that other way around.

On the other hand writing in Objective-C can give you access to lower level resources when compared to Swift. Sometimes we can do more in Objective-C which brings us to the other topic. When using Swift, you can still implement Objective-C code with no problem at all. And with only little tweaking, you can also include C and C++ code just as that.

Summing up 

Picking a technology is not an easy choice – so trust your digital agency with it. They will recommend the best solutions and then create an app that will become an essential part of your business.

Contact us, so we can talk about your ideas and goals. Who knows, maybe your mobile app will become the next big hit? To achieve that, you need great quality of code and sophisticated IT services. You can find all that at iteo.