In 2014, Apple’s decision to introduce Swift, another programming language for native iOS development, baffled the community. Moreover, Apple firmly stated that it would continue to support Objective-C as the iOS code language thus adopting two languages simultaneously into its platforms. This duality resulted in years of debates, tests and comparisons in order find out what is better, Swift or Objective-C. Let’s take a closer look at this phenomena, compare Objective-C versus Swift using the relevant language features as criteria, and try to determine the most efficient iPhone coding language.
- The evolution of Apple’s primary programming languages
- Comparison of iOS-native languages
- Final thoughts
The evolution of Apple’s primary programming languages
The first and most obvious difference between Objective-C and Swift is their age. At the first glance, it is a classic standoff of age and experience versus youth and resourcefulness. Despite the fact that both these languages are general-purpose, their approaches to programming differ drastically. While Objective-C is object-oriented, Swift supports multiple programming paradigms and, thus, seems more versatile and flexible.
The origins and backgrounds of these languages are also very different. Objective-C had a long and bumpy road towards its current state changing teams and owners from time to time. On the contrast, Apple has been carefully leading Swift by the hand like a beloved child while removing all obstacles on its way.
Brief history of Objective-C
Among currently widespread programming languages, Objective-C is one of the oldest, being over 35 years of age. This lengthy period allowed it to attract a numerous community, and gather a valuable knowledge base, from beginner guides to comprehensive manuals or specific examples of ad-hoc solutions.
Early 1980s - Brad Cox and Tom Love designed Objective-C – an extension of the C programming language that was heavily inspired by the capabilities of the Smalltalk language.
1986 - Objective-C is described in the book “Object-Oriented Programming, An Evolutionary Approach” by Brad Cox.
1988 - NeXT, Inc. founded by Steve Jobs acquires the licence for Objective-C and develops the GUI toolkit called “AppKit” and the framework called “Foundation Kit” to use this language in NeXT software products. Eventually, NeXT included Objective-C into the GNU Compiler Collection.
1992 - After several years of legal struggles caused by the terms of the GNU General Public Licence related to runtime libraries, the GNU Objective-C runtime is released. It was the reworked version of the NeXT’s original runtime from 1980s and was heavily modified one year later.
1996 - Apple purchases NeXT with all its intellectual products including Objective-C, the Project Builder IDE, and the Interface Builder application.
2003 - as a part of Mac OS X 10.3 (Panther), Apple releases the first version of the Xcode IDE that is based on Project Builder and supports Objective-C.
2007 - Mac OS X 10.5 (Leopard) introduces Objective-C 2.0 that had many functional improvements, most notably – garbage collection and better syntax. The first generation of iPhones is released, adding a new platform for app development.
2008 - Apple releases a software development kit for iOS that allowed third-party app development for iPhones using Objective-C, among other languages. For six years, Objective-C remained the only programming language for writing native iOS apps.
Brief history of SwiftSwift is still relatively new and may seem extremely young in comparison to Objective-C. However, thanks to its rapid development and exhaustive support from Apple, Swift is a powerful modern programming language for current and future Apple devices and platforms.
2010-2014 – pre-introduction research and development. Chris Lattner, a Senior Director from Apple’s Developers Tools Department, defined the concepts of the new programming language. Eventually, he convinced the management and several programmers who worked on the Clang compiler, to extend his idea to a full-scale development “ecosystem.” However, only in 2013 they found a way to make Objective-C and Swift coexist in a way that prevented chaos in the iOS community.
April 2014 – Apple introduces Swift at the Worldwide Developers Conference. Later, its beta version became available to the registered developers.
September 2014 – the release of the 1.0 version simultaneously with the Xcode 6.0 environment, the first version of this IDE that supports Swift.
October 2014 - April 2015 – Swift 1.1 and 1.2 are released along with Xcode 6.1 and 6.3, respectively.
2015 - Swift 2.0 is released. The programming language becomes open-sourced and its source code is published on GitHub. Also, according to the annual Stack Overflow Developer Survey, Swift is voted the most loved programming language.
2016 - Swift 3.0 is released. Swift wins the second place in the “Most loved Programming Language” nomination in the aforementioned survey.
2017 - Swift 4.0 is released. Chris Lattner, the creator of Swift, is hired by Tesla Motors, and Ted Kremenek becomes the leader of the Swift project.
2019 - Swift 5.0 is released as part of Xcode 10.2 that also contained a code migrator. One of the core achievements of this version is ABI stability. Additionally, new releases of the whole ecosystem of Apple operating systems (macOS, iOS, tvOS, watchOS, and iPadOS) now comprise Swift core libraries.
Comparison of iOS-native languages
In order to make the comparison as unbiased as possible, it must be performed using the same criteria. The brief results of each comparison stage are presented in the table below and described in full details in the following paragraphs.
Let us review each of these differences in more details and find answers to several frequently asked questions.
The most obvious criterion for comparing Swift programming vs Objective-C coding is the speed of resulting applications. Objective-C is far more mature and well-tested than Swift. For this reason, “Is Objective-C faster than Swift?” is one of the most discussed topics among novice iOS developers. Yes, in its current state Swift more or less outperforms Objective-C in most use scenarios. But let’s look deeper into this issue: the answer may surprise you.
As its name suggests, Swift was designed in such a way that ensures high speed as one of its core priorities. Apple states that Swift is about 2.6 times faster than Objective-C and 8.4 times faster than Python. However, the actual usage experience is not always consistent with the official statistics.
Initially, Swift offered roughly the same performance as C-based languages, including Objective-C. However, due to constant improvements implemented in new releases, this young language is noticeably faster than its old rival as well as its previous versions. On the other hand, it should be noted that Objective-C still compiles code faster than Swift.
Due to its traditional syntax, coding in Objective-C involves frequent use of many service symbols, most notably – semicolons, parenteses, brackets, etc. In contrast, Swift offers a simple and expressive syntax that has many features highly demanded by developers. For example, Apple developed Swift as a “type-safe” language that has its own variants of types present in Objective-C, as well as introduced several unique ones, e.g. tuples, and the concept of an optional type.
The simplicity of the syntax brings several important benefits such as the lower number of code lines, better readability, low entry level for developers, etc. These derived advantages will be described in more details below.
3. Difficulty to learn and read
Swift was developed in view of maximum code clarity. The simple syntax greatly facilitates programming, improves code readability, and makes Swift an easier language to master, in comparison with Objective-C. However, the lower entry level for new programmers did not turn Swift into some sort of “iPhone coding language for kids”; it still requires a great deal of dedication, diligence, and talent.
On the other hand, the impressive age of Objective-C resulted in creation of an immense knowledge base that contains manuals and advice for a wide scope of problems and skill levels. While Swift is considered generally easier to read and learn than Objective-C, the latter still has a larger volume of educational materials for any potential learner.
4. Code length
In addition to better readability, Swift code is also more more compact in comparison with Objective-C. First of all, it has the means to get rid of class prefixes, and it does not require header files; this feature reduces the number of project files by half in comparison with Objective-C. In addition, the simplicity of the Swift syntax allows implementing a feature with less lines of code than by using Objective-C for the same feature.
5. Errors and debugging
In Objective-C, the improper use of null pointers may potentially break the code without actually crashing an app or showing an error to the programmer. What is worse, the pointers may be potential vulnerabilities in the code that compromise the safety of an app due to their “silent” behavior, for example when a method is called with a nil pointer.
In contrast, every time Swift tries to process a bad piece of code, it triggers a compiler error. This feature simplifies bug tracking and allows fixing code errors immediately before the software project moves to a further stage of development. This bug-catching approach that results from error handling techniques combined with an improved typing system promotes safety and saves time required to ensure app stability.
6. Number of language “speakers”
During its 35+ year history, Objective-C has naturally established a numerous community of devoted programmers. Due to the length of the given period, many of them are experts who had plenty of time to hone their skills. Another crucial feature that attracts both software developers and their clients to Objective-C is the proven stability of the language in the hands of a skillful master who can handle the complex syntax and error-prone use of pointers.
Swift’s relatively short history is characterized by a burst of popularity that resulted in a rapidly rising number of followers, and an equally growing volume of educational content available both on and off the web. In just a year after its release, Swift managed to win the “Most loved coding language” title on a famous Stack Overflow website, and took a second place a year later, in 2016.
As of 2019, Swift is no longer among the leaders in “Most popular” or “Most loved” categories; however, it still beats Objective-C by a considerable degree in those ratings. It is worth mentioning that since 2016, Objective-C has been making its way through the list of “Most dreaded” programming languages and hit the second place in 2019.
7. Memory use
Both Swift and Objective-C support Automatic Reference Counting as a memory management feature. Objective-C 2.0 initially had a garbage collection feature that was later substituted in favor of ARC, while Swift supported ARC from its start. Though ARC is considered as an improvement over tracing garbage collection, it does not perform automatic handling of reference cycles. That is, if an object has strong references leading to it, ARC cannot reallocate the said object.
8. Use of dynamic libraries
Objective-C uses static libraries that are usually integrated within a program’s executable file and cannot be modified without recompiling the relevant .exe file. This way, such integration may protect a library from tampering or corruption, making an app more reliable. Additionally, the built-in static libraries increase the execution speed of relevant programs since they are an integral part of the software.
In contrast, Swift uses dynamic libraries that are situated outside the program’s .exe file, and can be shared among different programs. Due to their location, dynamic libraries may be updated separately from the relevant applications and more frequently than the static libraries, which is a huge benefit both for developers and software users. One dynamic library may be used by multiple applications and may be loaded on demand. This feature allows developers to reduce the size of applications because they do not have to integrate the libraries into the apps during compilation.
9. Support from Apple and long-term perspective
Both languages are officially supported by Apple as truly native languages for their operating systems. They both use the Xcode IDE that with every update brings new development features and bugfixes to the whole development toolkit, including the Clang compiler and the Swift compiler. For example, Apple offers the Core ML 3 framework for building machine learning applications using Xcode. It is also worth mentioning that Apple’s Cocoa Touch, a UI framework for iOS app development, is mainly written on Objective-C.
In 2019, Swift 5 finally achieved the long-awaited ABI stability which means that the phase of chaotic development and painful transitions between language versions is over. A stable Application Binary Interface means better compatibility for current and future versions of Swift, and allows including standard libraries into operating systems.
From the technical point of view, it is possible to combine Swift and Objective-C in one application regardless of the original project language. Apple enabled this opportunity in Xcode with the help of bridging header files. This way developers may use the most optimal language for each particular need and simply mix them together in the compiler. However, if a project relies heavily on a large number of C++ libraries, Objective-C would be more preferable than Swift.
Another important fact that developers should keep in mind is that Swift only supports the following or newer versions of the target operating systems: macOS 10.9.0, iOS 7.0, watchOS 2.0, and tvOS 9.0. If an app must be developed for older platforms, the programmers have to use Objective-C.
The comparison of Swift versus Objective-C proves that, as of this moment, it is too early to disregard Objective-C as an effective iPhone app development language. While Swift turned out slightly better almost in every aspect of this matching, its advantage is far from overwhelming. For instance, Objective-C is considered a more stable language that additionally allows using C and C++ libraries, as well as faster compile time.
Let’s sum up the results: Both languages have their pros and cons. Swift is much newer, somewhat easier, and is still being actively developed. It is faster than Objective-C is most scenarios of use, though the difference in performance is not always noticeable. Both languages are supported by Apple, have numerous communities of devoted fans and significant knowledge bases.
For these reasons, aspiring mobile developers should definitely go for Swift as an iOS code language, first of all because it is easier. However, many programmers who have mastered Objective-C still believe that Swift in its current state isn’t worth switching to, as its current and potential advantages may not cover the cost of learning it and abandoning Objective-C. Without a doubt, a team of skilled Objective-C developers is more than capable to provide a competitive solution even if none of them have not mastered Swift yet.In Light IT, we have specialists with high expertise in both or at least one of Objective-C and Swift. If you have a software project for any Apple device, contact us and we will turn your idea into the pearl of the App store!
Leave your comment