In June 2014 something happened that no one expected: Apple has introduced a new object-oriented programming language - Swift, which is slowly replacing Objective-C, previously used to develop applications for OSX & iOS.
Since the new iOS app programming language has been launched, disputes about Swift's advantages and disadvantages continue to simmer till now.
Is it worth making the switch to the more approachable, full-featured (as Apple Corp. claims) Swift for iOS or continue to use Objective-C in your projects?
What are the advantages of Swift over Objective-C? Which one should you choose for your project?
Let's sort all this mess out and see what's really going on.
This article will help you understand Objective-C vs. Swift differences and make clear what it means not only for developers but for your business in particular.
Apple has announced Swift as a powerful and intuitive programming language for macOS, iOS, watchOS, and tvOS that completely can replace Objective-C.
Due to several key features, Swift has the potential to become the only preferred programming language for creating engaging, flexible, consumer-friendly applications.
Before focusing on the Swift vs. Objective-C comparison, let us give a brief background to the history of iOS programming language development.
In distant 2008 Apple has released the iPhone SDK 2.0. This event caused the revolution in software development and gave the impulse to a new generation of developers. Today you know them as iOS developers. That was a real challenge for many of them to develop apps on Objective-C because they had had no experience with it before.
Later, in 2010 Apple launched version 4 of the iPhone OS (the previous name of iOS). The updated version comprised not only the new features in software but the changes in the Developer Agreement. According to the new usage agreement, applications must be originally written in Objective-C, C, C++ … and only code is written in C, C++, and Objective-C may compile and directly link against the Documented APIs.
The official reason for such an unexpected bombshell was Steve Job’s desire to prevent the usage of cross-platform tools such as Flash CS5.
Nevertheless, the changes in the apps policy provided by Apple were successful and helped the company populate the App Store with thousands of apps.
But in reality, Objective-C’s popularity was a result of the growing app ecosystem, but not vice versa.
In fact, many developers were dissatisfied with Objective-C at that moment, and this has given rise to many attempts to write iPhone apps in other programming languages.
Apple continually worked on Objective-C improvements with each release, adding blocks and literals, simplified memory management with automatic reference counting.
Having worked for 6 years on Objective-C improvements, Apple Corp has to admit the fact that it might not be the best coding language for writing mobile apps. So, it was decided to arrange another challenge for developers by introducing a new iOS coding language called Swift.
Apple announced that Swift code is safe by design and it is interactive and fun to write apps on it. Also, Swift syntax is considered to be easy to learn.
Apple has done a great job and implemented big changes in the new iOS coding language. These innovations have removed unsafe pointer management and introduced powerful new features.
At the same time, the interaction with both Objective-C and C is maintained. Swift provides a great speed that ensures real-time feedback and can be smoothly included in existing Objective-C code.
It means that code written on Swift is able to work with code written in C programming languages or Objective-C within the same project.
- Swift is not a strict superset of the C language. It means that Swift is free to make use of syntax constructs. For instance, this allows it to implement custom operators in Swift.
- Swift is statically typed, not dynamically typed. Swift can take advantage of many of the recent advances in type systems.
The pundits admit: the main Swift’s advantage is in its code, which is easy to read and write.
The number of code lines needed to implement the option on Swift is a lot fewer than for the same option on Objective-C.
Swift supports inferred types, and that helps keep code clean and avoid minor mistakes.
Memory is managed automatically, so there is no need to type semi-colons. Swift also includes some elements borrowed from other languages. For example, named parameters brought forward from Objective-C. These features are realized in a clean syntax that makes APIs in Swift easy to read and support.
One more of Swift's great feature is that Swift was made open-source in its third release. So, a broad community of developers, both inside Apple and hundreds of outside contributors, can work together to make Swift even more magnificent.
Read also: iOS vs Android development the pros and cons
Since Swift's second release, The App Solutions developers have been experimenting with it inside our company. Because of the relative youth of Swift, we did our first project using Swift at the end of 2015. It was an app for startup Nuwbii, an amazing resource that helps local businesses promote their services. The APP Solutions team developed an iOS mobile application for this project based entirely on Swift.
Below we gathered and shared Swift advantages that we've discovered throughout our experience using this new language. There are five reasons why you should use Swift that our developers have spotted while working on the project Nuwbii in particular.
Really groovy stuff when you need to experiment with something, to check out, or to try something. Xcode provides the programmer with space for experiments. It looks like a simple editor window where you can write code. The code is compiled and executed immediately. There is no need to build the project, and then run the emulator in order to test it. Everything runs simultaneously: you write code and instantly see the result.
A special panel on the right is capable of displaying almost anything - from simple lines to the finite control elements, from simple images to the graph of the variable value changes during processing.
Swift has reduced the amount of code that is needed to implement repetitive statements and string manipulation.
With Objective-C, there were a lot of problems that caused app crashes.
For instance, the developers were faced with messing up the order or using the wrong string token.
Here, Swift win by providing a code that is now less error-prone because of its inline support for manipulating text strings and data.
And finally, classes are not divided into two parts anymore: the interface and the implementation. This halves the number of files in the project, which makes it easier to navigate through it.
Even the name of the new framework - Swift - implies it's swiftness (pun intended.) Apple continues to improve the speed at which Swift can run app logic. Swift is applying best practices and demonstrates the following results: in an 8.5-fold boost for FFT algorithm performance (compared to C++ with only a 1.1-time performance). Also Swift has outperformed C++ for the Mandelbrot algorithm by a factor of a mere 1.03.
To provide safety Swift triggers a runtime crash while you use a nil optional variable.
This crash enables consistent behavior, which makes easier the bug-fixing process because it forces the developer to fix the problem immediately. This gives the possibility to fix the bug sooner or completely avoid it in code.
Swift switched from static to dynamic libraries. Dynamic libraries are executable chunks of code that can be linked to an app. This feature helps current Swift apps connect with the newer versions of the language due to its constant evolution.
The model remains the same: Automatic Reference Counting (ARC) with strong & weak references. But weak references are now available via Optional values. Plus unowned references were added, which are used when the applying of strong references is unacceptable because of the creation of circular references (which lead to memory leaks).
|Semicolons are required||Types are inferred|
|Types must be declared||Functions are first-class objects|
|You have to have header files||Collections are typed using generics|
|You have to set pointers||You can manipulate strings easier|
|KVO and custom setters||Memory is automatically managed|
Now the developers shouldn’t think about memory for every digital object they have created. ARC handles all memory management at compile time and works across both procedural and object-oriented code.
Swift adds language features that make developers' code safer, faster, more reliable, and more predictable compared to Objective-C.
In 2015 Swift won first place in the nomination “Most Loved Programming Language” in the Stack Overflow Developer and took second place in 2016. In 2017, Swift overtook Objective-C on GitHub's review:
Swift is gaining popularity significantly quickly. This is one of the fastest-growing languages, according to GitHub, it is in 13th place in popularity now. More and more proficient developers are implementing Swift code in their apps. Among the great apps that were built on Swift are LinkedIn, Lyft, Yahoo Weather, and many others.
VSCO Cam chose Swift to build the latest version of their photography app for iOS.
Read also: How to make your app compatible with iOS 13
Since spring it is rumored that Google is considering using Swift as a first-class language for its operating system Android.
After Swift was going open source, representatives of three leading corporations - Google, Facebook, and Uber - conducted a meeting in London to discuss a new language. The Next Web sources say that Google is considering making Swift the main language for Android, while Facebook and Uber also intend to give Swift a central role in their developments.
But Swift is not portable across platforms, and you can’t just copy-paste it. So, Android as the minimum would need the execution environment (runtime) for Swift - and that's just to start. Google also has to change all its standard libraries for Swift, as well as to implement the language support in APIs and SDKs.
However, using Swift for Android isn’t impossible. The developer Romain Goyet worked with Swift on Android - and has gained some success. Although it was long before Swift moved to the open-source, it proves that such work can be done. He used the Android NDK, which allows implementing other languages on this platform.
Summarizing, we can state with complete confidence that Swift is the future of mobile development. Developers are able to write safer, more reliable code, save time, and cost to design amazing app experiences. The APP Solutions iOS developers are unified in the opinion that Swift passed the exam!
Want to receive reading suggestions once a month?
Subscribe to our newsletters