The good and the bad of Swift programming language

The Good and the Bad of Swift Programming Language

Do you know how the US differs from the rest of the world in terms of mobile preferences? According to Statcounter, the global market share of Android is about 72.7 percent, while that of iOS is 26.4 percent (as of August 2021). However, if we look at the US map, iOS is leading the race with 56.7 percent, and its rival has 43 percent.

Having in mind so many people’s unfading loyalty to Apple devices, iOS app development is more relevant than ever. What you have to choose is the right tech stack for your product. If you decide to go for native development instead of cross-platform solutions, you still have to decide which language to use: the good old Objective-C or brand-new Swift.

What is Swift and why should you use it?

Swift is a compiled programming language for iOS, macOS, watchOS, tvOS, and Linux applications. Here’s what you need to know about Swift.

Created by Apple in 2014. Backed up by one of the most influential tech companies in the world, Swift is set to become the dominant language for iOS development and beyond.

Open source. Swift creators acknowledged the fact that in order to build a defining programming language, the technology needs to be open for all. So, within its seven years of existence, Swift acquired a large supportive community and an abundance of third-party tools.

Safe. Its syntax encourages you to write clean and consistent code which may even feel strict at times. Swift provides safeguards to prevent errors and improve readability.

Fast. Swift was built with performance in mind. Not only does its simple syntax and hand-holding help you develop faster, but it also lives up to its name: As stated on apple.com, Swift is up to 2.6x faster than Objective-C and 8.4x faster than Python.

In demand. Remaining supreme to Objective C, Swift was ranked 20th among the most popular programming languages of 2021 (while Objective C is ranked 25th) and 8th among the most loved languages.

Keep reading to learn more about the technology or visit the following links if you want to jump right into development with Swift:

Download and read the documentation on the Official Swift Community website

Download Xcode IDE to get started with Swift on macOS

Visit Swift repository on GitHub to contribute or dive into technical details of the language use

Learn Swift via interactive Swift Playgrounds on iPad

Connect with fellow developers by asking and answering Swift questions on StackOverflow

Watch the presentation of the latest Swift 5.5 at WWDC to discover new features

A Brief History of Swift Language

2013-2014 - creation and launch

First introduced at Apple's 2014 Worldwide Developers Conference (WWDC), the Swift programming language has generated considerable debate ever since. Chris Lattner, Apple's Senior Director, Developer Tools Department, started designing the basic concepts of the new language back in 2010.

Initially, it was really just me messing around and nobody knew about it because it wasn't anything to know about. But eventually, it got a little bit more serious [...] So I started talking to my management and some of the engineers that were working on Clang, and they seemed excited about it. We got a couple people working on it part-time and I convinced my manager that it was interesting enough that we could have a couple of people work on it.

- Chris Lattner for Accidental Tech Podcast, January 2017

It wasn’t until 2013 that the team was able to solve a strategic question about how the new language would fit in with the existing Objective-C ecosystem. Forcing all iOS developers to move to a new language could have had a major disruptive effect on the community. So, the company decided to continue investing in Objective-C while also committing to the development of a new “safe programming language.

One year later, the registered Apple developers were able to lay their hands on the beta version of the new language. In the first month post its release as a part of Xcode tools, it was downloaded over 11 million times, according to Tim Cook.

The initial reactions to Swift were mixed at best. Some developers were delighted with its features, flexibility, and simplicity, while others criticized it. Yet, most of them agreed that it was too early for Swift to be used in production. The language was evolving fast: major changes were introduced with every new release.

This, however, didn’t prevent Swift from becoming the “most loved” technology of 2015:
Most loved technologies, 2015 StackOverflow Developer Surve

StackOverflow survey results on most loved technologies, source: 2015 StackOverflow Developer Survey

At the same time, the language was listed among the top 10 “most wanted” technologies.

2015 - turning open source

Since Apple decided to make Swift an open sourced language in 2015, its growth has been tremendous. Over 60,000 people took a clone of the Swift project in the first week after the announcement.

2019 - stable ABI and backward compatibility

In March 2019, Swift 5.0 was officially released. It introduced a stable version of the application binary interface (ABI) across Apple’s platforms. That was a giant step toward helping developers use Swift on dedicated OSs like iOS, macOS, tvOS, watchOS and upcoming iPadOS. Needless to say, Apple is building a solid ecosystem, as now standard Swift libraries are included in OS releases.

SwiftUI was introduced in the release, which is basically a library of controls, graphic elements, and layouts for Swift applications that can be used to design user interface. The update also brought renewed documentation, updated CLI Xcode 10.2, and binaries for Ubuntu. Swift also became backward compatible with its previous versions. The list of languages that it is interoperable with now includes Ruby, Python, and JavaScript.

2020, 2021 -- support for Linux and Windows, concurrency, and actors

The Swift 5.3 release of September 2020 brought the long-awaited extension of official platform support, including Windows and additional Linux distributions. Since then, the full Swift ecosystem is available on the Windows platform. This includes the compiler, the standard library, and the core libraries (dispatch, Foundation, and XCTest).

The latest version, Swift 5.5 is still in beta (as of September 2021) and is available with Xcode 13 beta. It holds such improvements as better concurrency support using async/await mechanisms and actors. Actors are a reference type similar to classes, but in contrast to classes, they allow only one task to access their mutable state at a time. There’s also support for sendable data, which is the data that can safely be transferred to another thread.

Pros of Using Swift for iOS Native Development

Often referred to as “Objective-C, without the C,” Swift language is in many aspects superior to its predecessor. To get an in-depth comparison of Swift and Objective C, check our separate article. According to the official press release, “Swift combines the performance and efficiency of compiled languages with the simplicity and interactivity of popular scripting languages.” Leaving technology details and marketing aside, let’s see what it really means from a business perspective.

Rapid development process

A clean and expressive language with a simplified syntax and grammar, Swift is easier to read and write. It is very concise, which means less code is required to perform the same task, as compared to Objective-C. Automatic Reference Counting (ARC) does all the work tracking and managing the app’s memory usage, so developers don’t need to spend time and effort doing that manually. Accordingly, it usually takes less time to build iOS apps with Swift.

A shining example of this advantage is the Lyft app: The company completely re-wrote its iOS app using Swift. While the old codebase consisted of about 75,000 lines of code, the Swift version recreated the same functionality with less than a third of that. Moreover, the app now featured a new onboarding process: While the old one took more than a month and multiple engineers to implement, the new onboarding with Swift was completed within a week with only one engineer.

Easier to scale the product and the team

In addition to faster development time, you get a product that is future-proof and can be extended with new features as needed. Thus, Swift projects are typically easier to scale. The fact that Apple is more likely to support Swift than Objective-C should also get serious consideration for long-term investment.

Moreover, Swift allows you to add more developers to your team if needed: The onboarding is relatively fast due to the simplicity and conciseness of the codebase. The syntax of Swift is considered near to natural English, thus it offers easy readability for new team members.

Swift syntax function names

Swift syntax is easy to read because of logical English function names, source: extremetech.com

Improved performance, speed of development, and safety

As suggested by its name, Swift is made to be… well, swift. With a focus on performance and speed, the language was initially designed to outperform its predecessor. Namely, the initial release claimed a 40 percent increase in performance, as compared to Objective-C.

Besides, Swift was built with the LLVM compiler framework, which translates the assembly language to the machine code and optimizes the code, making development faster.

Over the years, multiple benchmarks and tests conducted by individual developers have proved that. Moreover, there are many ways to optimize Swift code for even better performance.

Another of Swift’s strengths is its safety. Its strong typing system and error handling prevents code crashes and errors in production. Thus, Swift has a shorter feedback loop, allowing you to see the errors in the code instantly and fix them on the fly, greatly reducing the time and effort needed for bug fixing and eliminating the risks of deploying low quality code.

Decreased memory footprint

When you build an app, you use a lot of third-party code - reusable and often open source frameworks or libraries compiled into your app’s code. These libraries can be static and dynamic (or shared).  You can probably guess that static libraries are locked into code at the time you compiled them, become the part of your executable file, thus increasing its size and load time. They also can’t be automatically updated since they’re stuck in the version you compiled at. Dynamic libraries, on the other hand, exist outside of your code and are uploaded only when needed. Static libraries need to have copies in all files of your program while dynamic ones only need one. Swift first introduced dynamic libraries to iOS when it launched.

Since the release version 5.0, standard Swift libraries are integrated into every macOS, iOS, tvOS, and watchOS release. That means any app built on those platforms will be smaller, because these libraries are included. With this advancement, stable application binary interface (ABI) was also released. That allows Apple to provide support of Swift across its platforms.

Interoperability with Objective-C

As Jordan Morgan, iOS developer at Buffer, wrote in his Medium post, “[...] swift is the new toy and marked as the future. Objective-C is showing its age and will, eventually, be much less prevalent. But in the here and the now, the two must learn to coexist peacefully.” Accordingly, there are two possible scenarios for using both in the same project: You either add new features in Swift to the existing Objective-C codebase, or use Objective-C elements in your new Swift project.

Either way, Swift language is perfectly compatible with Objective-C and can be used interchangeably within the same project. This is especially useful for large projects that are being extended or updated: You can still add more features with Swift, taking advantage of the existing Objective-C codebase. Thus, the porting process becomes easier and more risk-free.

Automatic memory management with ARC

Swift uses Automatic Reference Counting (ARC) - a technology aimed to add a garbage collector function that wasn’t introduced to iOS before. Languages like Java, C#, and Go use garbage collectors to delete class instances that are no longer used. They are useful to decrease your memory footprint but can add up to 20 percent to CPU. Before ARC, iOS developers had to manage memory manually and constantly manage retain counts of every class. Swift’s ARC determines which instances are no longer in use and gets rid of them on your behalf. It allows you to increase your app’s performance without lagging your memory or CPU.

Full stack potential and cross-device support

Actively pushed forward by IBM, the initiative to put the language in the cloud has been pretty successful so far. Server-side Swift integrates with most of the popular backend technologies. Just like in full stack JavaScript development, using Swift on both backend and frontend of your app allows for extensive code sharing and reuse, speeding up the development process and reducing development efforts.

Moreover, Apple provided support for all its devices: Mac, MacBooks, iPhones, iPads, Apple TV, and Apple Watch. Aside from Apples’, there is also support for Linux and Windows platform.

Vibrant open source community and learnability

As Apple’s Senior VP of Software Engineering, Craig Federighi, mentioned "We saw open sourcing as a critical element to make Swift reach its potential to be the language, the major language for the next 20 years of programming in our industry.”

Indeed, with the strong corporate support from Apple and IBM, Swift has quickly gained one of the most active and vibrant open source communities. The adoption trends, mentioned earlier are a case in point. Besides, Swift is among the top 5 most starred languages on GitHub, coming after Go, TypeScript, and Rust.

a list of actively developed programming languages github

GitHub list of the most actively developed languages, source: github.com

For such a young language, Swift sure has an abundance of resources to help developers accelerate adoption. Apart from official e-books, there are tons of community guidelines, podcasts, online and real-life courses, third-party apps, and of course Swift Playgrounds - a gamified learning experiences from Apple.

The Cons of Swift Programming Language

While there seem to be so many reasons to love Swift, the language is still far from perfect. Many developers and business owners are overly cautious when it comes to switching to the new language. There are several reasons for that.

The language is still quite young

Swift was introduced to the world in 2014, which seems to be long ago, but the language itself is really only 7 years old, compared to Objective C live since the 1980s. The recent update brought ABI stability across Apple’s platforms, backward compatibility of Swift versions, and renewed documentation. Those are huge steps toward making Swift a more mature language.

But, at the same time, these steps, i.e., frequent updates and changes, often make developers doubt if their today’s code will be compatible with previous versions tomorrow and if their project can be compiled at all.

Limited talent pool

While the Swift community is growing fast, it is still significantly smaller as compared to any other open source language. According to the latest StackOverflow Developer Survey, only 5.1 percent of the 83,053 respondents use Swift. It means that if you decide to create your next project using Swift, you might struggle with finding developers that are experienced enough with it.

stack overflow survey 2021

StackOverflow Developer Survey 2021

Poor interoperability with third-party tools and IDEs

Largely due to frequent updates, as mentioned above, it is often hard to find the right tools to help with certain tasks. Moreover, the official Apple IDE, XCode, lags in terms of tooling and support for Swift. Developers often report issues with syntax highlighting, autocomplete, refactoring tools, and compilers.

Incomplete cross-platform support

As we mentioned earlier, Swift supports all Apple platforms, as well as Linux and Windows. However, it was originally created and still works best for native iOS development, leaving the cross-platform market to React Native, Xamarin, and Flutter.

Lack of support for earlier iOS versions

You can only use Swift in the apps that target iOS7 and later. That said, Swift can’t be used for legacy projects running on older versions of the operating system. It’s not that significant since only a tiny percent of Apple devices currently run on iOS6 or earlier versions, but you still have to keep that in mind, you know, just in case.

Objective-C over Swift? Comparing use cases

A big part of making a choice between programming languages is your team’s experience and preferences. If your developers are skilled at Objective-C, having them all migrate to Swift may not be an option. Besides, even though Swift boasts regular updates and compatibility with modern tools, Objective-C accumulated a significant code base, third-party frameworks, libraries, and tools throughout its existence, as well as a vast number of apps built with it. So, let’s unpack in which cases you might want to stick with Objective-C over Swift.

Maintaining an Objective-C app

If you have to maintain a functioning application that is written in Objective-C and has a substantial code base, it just doesn’t make sense to rewrite it in Swift.

Old OS versions support

Being a new language, Swift supports only iOS 7 and macOS 10.9 or higher. If you have a reason to build  or maintain apps that should run on older versions, you don’t have any other choice rather than using Objective-C.

Tight deadlines

Learning a language, even a simple one like Swift, takes time and effort that many projects lack. If you don’t have the luxury of postponing your app release until members of your team get comfortable with Swift, you should consider sticking to ObjC. In case the time allows, learning Swift would definitely be beneficial in the long run, considering that Apple doesn’t plan to stop its development.

Big project size

Swift is young, which is why smaller apps can get around updates much easier. In the cons section, we mentioned that rewriting your program with each version release may be a struggle, so until this issue is fully fixed, you wouldn’t want to risk long lists of changes.

Using C or C++ third-party frameworks

Being a superset of C, Objective-C allows you to comfortably and smoothly use C and C++ libraries. While the need to exclusively import C++ files is a rare case, you should be aware that Swift doesn’t have that supported. To use the C++ code, an Objective-C or C wrapper must be created between Swift and C++.

Swift Playgrounds and other learning tools

After deciding if Swift is good or bad for you, you may ask how to learn it. As any open-source project, Swift has increased in both platforms and people to learn the language from. We’ve mentioned some of them, but let’s gather the information concerning those resources here.

The best way to get practical knowledge and actually learn to code with Swift in a fun and interactive way is the Swift Playgrounds.

Swift Playgrounds is a development environment integrated into Xcode on MacOS, or it can be installed as an app on the iPad. It is basically a training program that will teach you interactively how to code stuff with Swift.

swift playgrounds interface

Swift Playgrounds gamified approach to training, source: Swift Playgrounds

If you prefer to start with the theory, there are a lot of official Apple resources.

App Development with Swift is a book explaining the basics and advances of the language, and serves as a required theoretical base if you want to become a Swift developer.

Intro to App Development with Swift will teach you how to actually create an application with Swift as a practical course.

There are also alternative places to learn the language. Most links to useful resources are gathered on the Hacking with Swift page on how to learn Swift for free. There you will find manuals, videos, podcasts, web courses, and their own resources on the topic. The creator of Hacking with Swift is Paul Hudson, who posts news and guides on Swift on his YouTube channel, so it might come in handy as well.

Concerning the latest version of Swift, consider running through official guides on the latest 5.5 version. The last but not least important stop on your trip might be Swift documentation, which has a structured view of libraries, data models, and language interoperability.

IDEs to be used with Swift

IDE (Integrated Development Environment) is the main point of interaction with the language. Here we’ll discuss IDEs that can be used for Swift.

Xcode. In most cases, the native Apple's IDE Xcode will be enough for Swift engineering. It has a convenient interface, autocompletion support, and many other features that make Swift engineering smooth. However, if you also need to use HTML, CSS, and JavaScript, Xcode will turn into a simple text editor lacking instruments available with Objective-C and Swift.

AppCode. This IDE for iOS and macOS developers was designed by JetBrains. The product is aimed at improving development performance by providing some refactoring tools similar to those available in Android Studio. And this perhaps is one of the main reasons why you might consider AppCode over Xcode. Unfortunately, AppCode still has limited functionality with Swift compared to Xcode, lacking storyboards, app validation, and submission. On top of that, AppCode comes with a subscription fee.

Atom. Atom text editor and IDE was created by GitHub. It shines if you combine plain iOS development with other platforms and languages. While Atom itself is basic, it has a great number of open source packages built by the GitHub community which will allow you to customize the IDE for cross-platform and versatile development with autocompletion, advanced navigation, and other useful features.

While you can also consider Visual Studio and some other IDEs for Swift, these three are on the list to check first as each one of them provides unique benefits of working with this language.

Swift toolkit

Except for IDEs that do offer a lot of essential features for code building, programmers use tons of other tools to facilitate the development process.

Swift libraries

Swift has a powerful Standard library of its own, which covers all the needed functionality for writing Swift apps. As Apple documentation describes it, this library allows developers to “solve complex problems and write high-performance, readable code.”

Besides, there is a Swift Core Libraries project that provides a higher level of functionality and contains a robust suite of APIs that are consistent across different platforms. That means the code will be portable to all platforms that Swift supports.

SwiftUI

In short, SwiftUI is a full-fledged framework for building user interfaces, mostly on Apple platforms. It was introduced in 2019 as part of XCode 11 and designed to replace the previously used UIKit and AppKit with better performance and ease of use.

SwiftUI uses a declarative syntax that allows you to easily create composable components called views.

swiftui syntax

SwiftUI syntax, source: XCode

Since it’s relatively new, SwiftUI still has some weak sides and imperfections such as limited API coverage compared to that of UIKit, but it keeps developing and is likely to become the main UI tool in iOS app building. As of now, it provides a complete UIKit and AppKit interoperability, giving you the flexibility to adopt SwiftUI in the existing project.

Swift Package Manager

Swift Package Manager is the tool that allows you to easily manage your dependencies, import third-party, open source libraries, and share your packages across your projects. You can also distribute your source code to the Swift community. Swift Package Manager is included in Swift 3.0 and above.

Third-party tools for Swift

We asked Anton Kaliuzhnyi, an iOS tech lead at AltexSoft, what are other essential tools that a Swift developer should know:

“In Swift, you must know standard libraries. It’s very important that a developer can use the established solutions instead of writing their own bicycle. However, there are other useful tools for different purposes that can enrich the standard Swift capabilities. For example, Alamofire is a powerful HTTP networking library for iOS and macOS that helps simplify a lot of networking tasks.

"Also, since you have to integrate with Google services often, you have to be familiar with Google Analytics, Crashlytics, Firebase Services, and so on.

"There are a number of useful libraries for downloading and caching images, e.g., Kingfisher, SDWebImage, or AlamofireImage.

"If your project requires authorization with Facebook, Facebook SDK will come in handy.

"Now, it’s becoming more and more popular to create Skeleton loaders. You can implement it using Windless or SkeletonView.

"In some of our projects, we used the MulticastDelegate that allowed us to create one-to-many delegate relationships, i.e., to inform multiple objects whenever a change has happened to another object. That greatly improved the performance of our app and helped avoid tons of bugs.

"Of course, it’s absolutely necessary to use the tools for autogenerating Swift code for your project resources, e.g., SwiftGen and R.Swift, to save time and facilitate the development process.

"The world is actively moving towards SwiftUI, so it’s important to master it, as well as the Combine framework to work with asynchronous events.”

Can Swift Be the Future of iOS Development?

Despite its age and the attendant controversy, Swift already has a number of prominent success stories. Some of the companies that chose the new language are Uber, Lyft, and Fitbit.

Swift is becoming a more mature language with every update, but there are still things to fix. Apple is creating its own ecosystem with a stable ABI over its platforms, extending platform support, and continuously adding new features. You can see from our review that Swift has numerous advantages that outweigh its minor issues, so it remains one of the most promising languages and keeps gaining admirers.

Thus, we believe that Swift adoption will continue to grow, which soon might lead to a complete displacement of Objective-C as the leading first-class language for iOS mobile application development. For business owners, it is crucial to be ready for any changes the market might impose. So, preparing to switch to the new language with minimum effort and at a reasonable cost should be one of the key strategies for the near future.

This post is a part of our “The Good and the Bad” series. For more information about the pros and cons of the most popular technologies, see the other articles from the series:

The Good and the Bad of Angular Development

The Good and the Bad of Serverless Architecture

The Good and The Bad of Xamarin Mobile Development

The Good and the Bad of JavaScript Full Stack Development

The Good and the Bad of Node.js Web App Development

The Good and the Bad of ReactJS and React Native

The Good and the Bad of Selenium Test Automation Tool

The Good and the Bad of Android App Development

The Good and the Bad of Vue.js

The Good and the Bad of Java Programming

The Good and the Bad of React Native

The Good and the Bad of Katalon Studio Automation Testing Tool

Comments5

Sort by