Swift Pros and Cons: Building an iOS App
Simple to use and easy to read, Swift has changed the way iOS apps are developed and is making what wasn’t possible. Swift's compatibility and functionality across various Apple platforms, including iOS, macOS, iPadOS, tvOS, and watchOS, further enhance its appeal.
Before the advent of Swift, apps were primarily created with Objective-C, which was time-consuming and difficult. With Swift, the benefits it brings for app development are countless. Swift's clean syntax and memory management features contribute to a faster and less complex development process. Speed, security, user experience, and maintenance are just a few examples. Let’s consider these as we turn our attention to the use of the Swift programming language in iOS app development.
What is Swift programming language?
Created in 2014 by Apple, Swift is a programming language for iOS, iPadOS, macOS, tvOS, watchOS, and Linux applications. Emphasizing its stability and compatibility across Apple's platforms, Swift facilitates developers in creating applications that work seamlessly on various operating systems.
It wasn’t until 2015, though, that Apple decided to open source the code to boost greater adoption. Now, the Apple App Store has 1.96 million apps available to download, which are partially written in Swift. These include Airbnb, Facebook, LinkedIn, Lyft, Slack, and Uber.
Previously written in Objective-C, a programming language that dates back to the 1980s, Lyft is one example of an app that switched to Swift. The original version of Lyft had grown to 75,000 lines of code, but by moving to Swift the company recreated the app with the same functionality with less than a third of that.
Swift's open-source nature and rapid community support have established it as a defining programming language. Within a few years, the community has moved from the outdated Objective-C language to a modern, backward-compatible programming language that is easy to learn and read. For businesses seeking a programming language to develop an app, here are the pros and cons of Swift.
The advantages of Swift
Often referred to as “Objective-C, without the C,” Swift has many benefits compared to its predecessor.
It’s fast
The official Apple website claims that Swift is 2.6 times faster than Objective-C, helping with cost-saving measures. Swift's clean syntax and concise code contribute to a rapid development process, significantly reducing both development time and code complexity. It’s also easier to read and write. As noted above with the Lyft example, businesses can develop an iOS app using Swift quickly as it requires much less code than other languages.
It’s safe
Another of Swift’s strengths is its safety. It’s created to be a type-safe and memory-safe programming language. Type-safeness points to the language preventing any type errors. Memory-safe means that it avoids vulnerabilities linked to uninitialized pointers, which could lead to a program crashing. With a shorter feedback loop (this is when outputs are fed back as inputs, which determines the cause and effect of that loop), developers can see any code errors, reducing the time spent on debugging and removing the risk of low quality code.
Interoperable with Objective-C
By being compatible with Objective-C, Swift can be seamlessly integrated into the same project, making it easy to incorporate new Swift code into existing Objective-C applications. This is especially useful for big projects that are being updated as more features are added with Swift, which are then placed into Objective-C’s codebase.
Low maintenance
Once an app is built with Swift it’s easy to maintain. Swift's syntax promotes writing clean and consistent code, enhancing readability and preventing errors. Compared to Objective-C, which is managed in two separate files, Swift combines the Objective-C header (.m) and implementation files (.h) into a single program (.swift) file. One thing to note is that Swift has dependencies. Whereas, on MacOS, Swift is already installed and ready to go, on Linux to install Swift you need to install certain dependencies, like Python, first.
Better user experience
Apps developed with Swift require less time to install and less on-device memory, providing a better app experience for users.
Effective memory management
Swift uses a solution called Automatic Reference Counting (ARC) that builds upon its ObjectiveC predecessor. Swift also uses an LLVM compiler framework which translates assembly language to machine code, optimizing performance and improving development speed. The ARC determines which class instances are not being used and gets rid of them for developers. This gives developers more time to focus on the app’s performance without reducing its CPU or memory allocation.
ABI stability
Application Binary Interface (ABI) is a binary equivalent to an Application Programming Interface (API) for Swift. According to Swift, while ABI stability is a significant achievement for any programming language, “the ultimate benefit to the Swift ecosystem was to enable binary compatibility for apps and libraries.” In effect, the ABI allows code compiled using different versions of Swift, and even ObjectiveC, to communicate.
Use of optionals
Optionals are a programming concept that enables developers to prevent app crashes while ensuring clean code is maintained across the application. Think of it as a wrapper type, which wraps the value inside. An optional can either contain something or be empty. To know for sure, optionals need to be unwrapped, and if done properly won’t cause crashes.
The disadvantages of Swift
While Swift has been designed to make maintaining and writing app code easier for the developer, there are a few disadvantages to consider as well.
Swift is still a new language
Compared to Objective-C, which has been around since the 1980’s, Swift is a newcomer, having been created in 2014. The availability and importance of third-party tools play a crucial role in enhancing the Swift programming experience by providing essential resources and addressing interoperability challenges. This means it might suffer from growing pains. Despite recent updates with ABI Stability and backward compatibility, Swift is limited on tools and libraries.
Binary compatibility doesn’t always work
Even though ABI Stability is an advantage of Swift 5.1, code compiled with different versions of Swift can come into problems. When developers were primarily using Objective-C, code could have been compiled into a static library and introduced into a project as a dependency. Before the introduction of Swift’s ABI, it was not possible to create static libraries in Swift. While that’s now possible, there are issues implementing those dependencies into a project.
It’s not a reflective language
Compared to programming languages such as Java or Kotlin, Swift is not a reflective language. Instead, it offers an alternative: a Mirror functionality. With this, Swift can take an object and “self-describe” it, but it can’t manipulate it from within. If reflection was available in Swift, it would automatically inject dependencies, but it’s believed this would be difficult to achieve.
Small talent pool
This is another minor disadvantage, but it needs bringing up regardless. While Swift’s community is growing fast, it is still relatively small compared to other programming languages. The swift community, despite its smaller size, is expanding and offers substantial support and resources for both new and experienced developers. A 2019 developer survey from StackOverflow found that only 6.6% of over 87,000 respondents use Swift.
Learning a new language
While it’s an easy language to learn, it still requires time to understand Swift, which some projects may not have. If a business can delay the release of their app until team members are comfortable with Swift, this will be a good move in the long-term as Apple continues to invest in its development.
Swift apps examples
Several major companies, including Lyft, Airbnb, and LinkedIn, have embraced Swift for its modern capabilities and efficiency in app development. Swift code can coexist with Objective-C, improving performance and safety in software development.
For instance, Lyft transitioned from Objective-C to Swift to address the growing complexity of its codebase, successfully reducing the code size by over two-thirds while maintaining the same functionality. This change not only improved performance but also accelerated development cycles, enabling faster feature rollouts.
Similarly, Airbnb adopted Swift to leverage its advanced type safety and streamlined syntax, which contributed to a more robust app architecture and reduced the likelihood of runtime errors. LinkedIn integrated Swift to modernize its app’s user interface and optimize memory management, resulting in smoother performance for its growing user base.
These examples highlight the increasing trend of businesses moving to Swift as they prioritize agility, maintainability, and enhanced user experience in their mobile strategies.
Is Swift the future for iOS development?
Despite its young age, Swift is becoming a widely used programming language for iOS development. Swift projects are characterized by their fast development and scalability, making them future-proof.
A few of the companies that have already chosen Swift are Eventbrite, Kickstarter, LinkedIn, Twitter, and Whatsapp. Even though there are still teething issues to solve, Swift is turning into a mature language that could, eventually, see it displacing Objective-C as the go-to language for developing iOS apps.
In the long term, Swift will help businesses fill the mobile app gap. It’s a fast language that is easy to understand, it’s becoming a preferred choice for developers. As it’s an open-source platform it has a substantial community behind it with contributions from anyone who wishes to take part.
For businesses looking to make the switch to a language with the least amount of effort, Swift will continue to be a key component for app development in the future. If you’re looking for an opportunity to learn Swift, send us a message.