Is Swift the Objective Choice now?
‘Swift Vs Objective-C’- It is one of the first Google searches every iOS developer does before beginning their journey into the world of app development. At a broader level, choosing between Objective-C and Swift is also one of the fundamental and crucial decisions every business makes before beginning any iOS app development work.
So if the question is Swift or Objective-C? The answer cannot be in binary. If you have an existing application already written in Objective-C, then you can weigh the benefits of switching over to Swift vs sticking to Objective-C. However, if you are planning a new app, then Swift should be your default choice.
Why so? Well, read on to know…
………………………………………………………………………………………
The Story so far
Apple launched a new programming language called Swift in WWDC in October 2014. It came as a surprise to every developer as it was intended to replace Objective-C as the main programming language on Apple’s platforms, which by all means was stable, proven and had been around for more than two decades, powering millions of apps.
The goal was far-sighted. Swift was designed to be safer, faster, and easier to maintain. Though initially built for Apple platforms, it was aimed to be able to support all platforms. Before becoming Open Source, Swift was designed ground up by Apple using decades of Objective-C experience adding a modern touch derived from the latest programming trends and good practices. It was designed to have all the goodness of a modern-day programming language. Though a descendant of Objective-C, it is fundamentally different in terms of design, syntax, programming style and memory management.
But replacing a decades’ long programming language with a new one cannot be an overnight affair. There were thousands of libraries and hundreds of frameworks already written and working with Objective-C, as they were supposed to. Rewriting them using an infant language did not seem logical. Thus, Objective-C runtime continues to access Apple platform frameworks like UIKit, WatchKit, and AppKit. And Swift has the capability to interface seamlessly and work on top of it.
From the very beginning, Swift is fully compatible with Objective-C, as it should be. Both languages can still co-exist on all Apple platforms. And Apple isn’t likely to change this in the foreseeable future unless it has any strong reason to do that.
Support for interactive programming using Playground enables developers to test their idea live without building and running applications.
In terms of programming capabilities and flexibility, Swift has a lot to offer. Its functional programming style, and strongly typed language makes it impossible to have run time crashes resulting from out-of-bound or type-related issues. It has features like closures, tuples, generics, Structs and enums supporting methods, extensions and protocols, computed properties, powerful extensions, and the list just goes on…
Design-wise factors such as safety, readability, code size, less error-prone, efficient and fast iteration over collections, and other platform support make Swift fundamentally better than Objective-C.
………………………………………………………………………………………
Why Objective-C then?
Despite being so much powerful, Swift lacked just one thing that triggered Swift vs Objective-C debate, and that is ‘Maturity’. In the earlier years, deciding between Swift and Objective-C was like choosing between a fledgling with a lot of promise and a veteran with proven credentials.
Those who had rushed to develop production apps using Swift version 1 & 2, had to refactor the whole codebase, or just rewrite it again. It wasn’t matured, evolving rapidly, and syntaxes were completely changing in the early iterations. Hence, it was difficult to maintain Swift Apps compared to Objective-C, which was matured, trusted and possessed a huge developer base.
However, after Swift3, syntaxes became relatively stable and some minor refactoring that was needed was taken care of by the Xcode itself. And then Swift4 seemed to be more stable in terms of design and syntaxes, but, it still lacked ABI stability. Then came Swift 5.
………………………………………………………………………………………
What makes Swift 5 different?
So far, every version of Swift has been better than earlier. But what makes Swift5 so special is ABI stability.
Starting with version 4.2, Swift codes from one version have been compatible with another. However, the application binary, which can be considered as the machine level code for the sake of this argument, wasn’t compatible with that from a different version of Swift. That is, Swift wasn’t ABI stable until recently before version 5 was launched.
With Swift now being ABI stable for all Apple platforms like iOS, WatchOS, macOS and tvOS, all future versions of Swift including Swift5 will be compatible with each other at the binary level. True that Swift will continue to evolve in future releases, but the application written in the current version of Swift will no longer need to be refactored or rewritten to be able to support future versions of OS. In fact, libraries written now will seamlessly coexist and communicate at the binary level with code written in future versions of Swift and vice versa. And the reduction in app size is the immediate benefit it provides to the users now.
………………………………………………………………………………………
Conclusion
True Objective-C is here to stay. There are millions of applications already running using this. But, it isn’t getting any major updates, most of the updates are just to make it compatible with Swift. As a language, Swift is way superior. And above all, developers with expertise in Objective-C and practicing it will dwindle in years to come.
………………………………………………………………………………………
If you have any queries in this field, talk to Mindfire Solutions. For over 20+ years now, we have been the preferred Software Development Partner of over 1000+ Small and Medium-sized enterprises across the globe.