As a long-time mobile developer who is passionate for this ever-evolving ecosystem, I have always been interested in trying out any new framework or language that I came across. Ten years of working with mobile platforms has given me many opportunities to stand as a front row witness to ground-breaking progress.
The Swift language is definitely a step forward for any Apple developer, and it won’t be long till Objective-C is relegated to the category of ‘legacy code’. Today we will be covering the history of Swift, a young but promising language.
A Short History of Swift
Swift is known nowadays as the standard programming language for Apple developers. Since its release in 2014, the Apple developers community has welcomed it with open arms as a replacement to Objective-C, a language that most people would consider outdated compared to the main languages from other platforms.
Comparing different languages and platforms often turns into a battle of preferences and tastes, where the results and opinions are biased by the technological preferences of the author. However, Objective-C had one advantage that no one could deny, and it was a big one: performance.
In fact the very first question raised on many forums when Swift made its debut was ‘What about performance?’. People were concerned that the price for a more elegant language would be a noticeable performance hit, and the majority wouldn’t accept such an exchange.
Improvement With Later Versions
So, was Swift slow compared to Objective-C? Yes, yes it was, painfully slower. Many early adopters rejected the language because of this and encouraged the community to stick with Objective-C, with dooming statements like too slow for production.
Luckily, Apple turned things around quickly with the release of Swift 1.2, and the same author mentioned above wrote a new post about it, only this time performance was considered Pretty much fine. Both posts are worth reading.
With later releases (versions 2 and 3), Swift went through some breaking changes. These changes were pretty much necessary for the language to become mature and consistent. Swift became simpler, more predictable, and a more consistent language over the long term.
A noble goal for a growing language, but not without a price. Almost every release of Swift had breaking changes that required a considerable amount of adjustments on any app source code to be able to compile in the new version. Again, the community complaints were heard and with Swift 4 on the horizon, Apple set a primary goal for this new release, “to provide source stability for Swift 3 code.”
According to a statement from Apple’s documentation from a code migration perspective, the difference between Swift 3 and Swift 4 code is expected to be much smaller than the jump from Swift 2.2 to Swift 3.
So, What About Swift 4?
Swift 4 will provide a compilation mode (-swift-version 3) that will make things easier for people who are not ready to adopt the breaking changes introduced by this new version.
The overall objective of the Swift 4 release is to converge and align with the core goals and reach a maturity level that will provide more stable releases in the future. “As the releases converge, the criteria for pulling changes into 4 will become increasingly restrictive.” -swift.org/blog-.
Why Choose Swift Over Objective-C?
- Maintainability: Reduced boilerplate code, single files as opposed to Objective-C’s header and implementation files. This leads to less code, which translates to less maintenance required.
- Better Memory Management: While Objective-C had automatic reference counting, it’s not implemented for all APIs (e.g. Core Graphics). Swift provides automatic memory management for all APIs.
- Safer code: This comes as a result of simplifying pointers handling.
- Readability: Clearly, Swift is easier to read than Objective-C.
- Support for namespaces: No more name collisions when integrating multiple projects.
- Dynamic libraries: Reduced app size, flexibility and improved performance on loading times
- Performance: Continued improvements over Swift have placed the language next to C++ on many standard benchmarks.
Important Milestones
Swift has had some important achievements over the last couple of years:
- On June 2015, Apple made it Open Source with the Apache 2.0 license
- Support for running Swift code on Android!
- Server-side development
It’s nice to see languages and platforms evolving continuously in a natural way, focusing each iteration on a specific goal while tackling concerns from the community.
This evolution process applies to most technology-related scenarios. It’s not easy to try something new and ground-breaking. Innovation always comes along with criticism, but that synergy is what gives shape to great products.
And as the title for this article says, this is what I call a swift evolution.