With more than 700 million iPhones currently in use, iOS is the second-most popular mobile platform world over. While Android may be at an advantage worldwide market-share wise, in regions, like the US, France and the UK, Apple devices continue to dominate the market. This is why, so many businesses focus solely on iOS platform for their software products, as they see it is as their key investment opportunity.
If you are one of those businesses looking to follow the iOS app development, then you have a critical decision to make. That is of choosing the right tech stack for your product. What are you gonna go for? If it is the native development instead of cross-platform, then which language will you use? The good ole Objective-C or Swift?
Let’s take a look at the pros and cons of using Swift iOS development language.
What must you know about the language? What are the risks that accompany Swift? To proceed with advantages/disadvantages discussion, let’s first start with its background and history.
Swift- Its History and Background Story
Apple first introduced Swift in 2014 at WWDC (Worldwide Developers Conference) as a second official language for iOS, macOS, tvOS and watchOS development. A year later, it was made open-source. Just in September 2017, Swift 4.0 was released with new updates and compatibility modes.
In a press release, highlighting the news of the announcement of iOS 8, Apple had this to say about the new programming language.
“Swift is a powerful new programming language for iOS and OS X® that makes it easier than ever for developers to create incredible apps. Designed for Cocoa® and Cocoa Touch®, Swift combines the performance and efficiency of compiled languages with the simplicity and interactivity of popular scripting languages. By design, Swift helps developers write safer and more reliable code by eliminating entire categories of common programming errors, and coexists with Objective-C® code, so developers can easily integrate Swift into their existing apps. Xcode® Playgrounds make writing Swift code incredibly interactive by instantly displaying the output of Swift code”. – Apple Inc.
Despite its young age, it has swiftly climbed its way to the top to being placed on 11th position in TIOBE’s “world’s most popular programming languages”. This already places Swift 7 positions higher than its predecessor Objective-C, accomplishing its initial purpose. One of the reasons, why Swift has become so hugely popular in such a short period of time, is due to Apple’s brand recognition all over the globe. Yet, managing to gain the trust of millions of developers who were using a 30-year-old tried-n-trusted language is no simple feat.
So, let’s look at Swift advantages and disadvantages - what is driving its popularity as a major language of iOS development and its drawbacks that are restricting its growth respectively.
Developing iOS apps with Swift – Advantages of swift programming language
Easier to read- easier to maintain
Swift’s code closely resembles natural English and owes a lot of its syntaxes to more elegant languages such as C#, Python and Ruby. While on the other hand, Objective-C syntax is much closer to the intimidating syntax of C. Swift, as a result, is much transparent and is much more expressive with simplified syntax and grammar. In fact, Apple is so confident in the simplicity of Swift that it encourages children to create apps through games via Playgrounds.
Explaining Swift’s advantage, Cade Metz, Sr. staff writer of Wired writes –
“Part of Swift’s edge is that it’s built for the average programmer. It’s designed for coding even the simplest of mobile apps, and with a rather clever tool Apple calls “Playgrounds,” it offers an unusually effective way of teaching yourself to code”.
He further adds in how Swift is a completely different ball game than Google Go (developed in 2009 and is still struggling to gain followers), he cites Paul Jensen, a programming language analyst-
“With Google Go, there was no real incentive to use it…. The difference with Swift is that there is incentive (its transparency and simplicity over Objective-C).”
Plus, unlike Objective-C, Swift drops the two-file system, which removes the imposition of additional work on programmers that comes with Objective-C. It cuts out the boilerplate work and assists in improving the quality of code, features and comments that are supported.
Swift is Brief
One of the aims of Swift developers was to make the language concise. Owing to string interpolation alone, Swift is capable enough to reduce Objective-C mobile app code by almost 70 percent. Less code means faster development and testing- thus cheaper maintenance and less resource expended.
The transparency in its code leads to a faster development time. In addition to that, you also get a product that is “future-proof” and can be added with new features. This leads to easier scalability. Plus, for your long-term investments, you need to consider that Apple is more likely to support Swift rather than Objective-C.
Interoperability with Objective-C
Although not an outright pro over Objective-C, this feature is definitely a merit. As Jordan Morgan, an iOS developer at Buffer writes in his post –
“It’s no question — 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….. The other was tacked on to an aging programming language and repurposed for modern technology”.
Like Morgan says, Swift doesn’t completely replace Objective-C, which is and will stay a part of many mobile apps that will need maintenance in the future. Swift is completely interoperable with its predecessor and therefore can co-exist with it in one file, app or code line.
Safety and Improved Performance
As its name suggests, Swift is created to be – swift. It puts emphasis on speed and performance which initially was 40% more than Objective -C, on both accounts. With multiple yardsticks crossed and tests conducted by developers, this is more than evident.
Another advantage of Swift is safety. Owing to its robustness and statically-typed characteristic, Swift enables developers to determine bugs before compilation and thus fix them on the fly. Furthermore, Swift has smart nil-pointer safety measures that avert errors in compiling caused by null references.
Swift supports not only iPads and iPhones, but all Apple devices- like Apple watch, Apple TV and Mac.
Managing Memory Automatically
A point that Kevin Poniatowski had correctly predicted back in 2014, in his Security Innovation post is that of automatic memory management, he wrote –
“A feature I believe that many Objective C developers will be enjoying soon is that Swift will manage memory automatically. This will take care of some serious coding vulnerabilities like the annoying and potentially very dangerous “use after free” coding error”.
To prevent memory leaks and optimize app performance, Swift uses Automatic Reference Counting across all APIs. In simpler terms, it manages memory on its own- enabling consumption of resources in the most efficient manner. There is no need for manual memory settings and while making the required changes, developers are supported and guided by Swift’s conventional tools.
Strong Corporate Support from IBM and Apple
Both Apple and IBM have combined their efforts to invest in Swift. This has led to Swift gaining one of the most active open source communities. In fact, it is one of the most starred programming languages on GitHub.
Swift has many advantages, especially over its predecessor Objective-C, however it still suffers from some drawbacks.
Developing iOS apps – Swift Drawbacks
Lack of backward compatibility with older language versions (resolved partially)
Swift is often considered to be unstable due to major changes brought in with newer versions. Many developers had complained that even Xcode’s assistance in updating Swift code to newer versions doesn’t fix all issues, which makes shifting a project to the newer Swift version time consuming and costly.
In the newly released Swift 4.0, though, when you use Xcode to build Swift 3 code, most of the new Swift 4.0 functionality is available.
According to Apple’s Guide on Swift 4.0 -
“A target written in Swift 4 can depend on a target that’s written in Swift 3, and vice versa. This means, if you have a large project that’s divided into multiple frameworks, you can migrate your code from Swift 3 to Swift 4 one framework at a time”.
The earlier versions of the language had a lot of speed issues, however, with newer versions, the performance results are much better as mentioned above.
A New Language
Due to Swift being in its initial stage, there is much time for the language to mature and discover/ address its pain areas. It still has a very limited amount of “native” libraries and tools. Plus, due to its newness, there is a limited amount of Swift developers out there. Even so, since the swift community is growing rapidly, there is an increase in demand for Swift programmers.
Will Swift be the Future of iOS Development?
Despite being in its initial age, Swift is enjoying many success stories. In fact, its newest version, Swift 4.0 has brought tremendous improvement in its previous version, bringing better version compatibility- easing the process of migrating to Swift 4.0, updates to Swift Package Manager, API improvements and additions etc.
Among Swift’s prominent users are LinkedIn, Coursera, Pandora, Twitter, Fitbit and Vimeo etc., while Facebook and Uber have showed renewed interest in the language. Thus, as adoption rates grow, Swift can eventually replace Objective-C as the leading language for iOS development.