Main image of article Swift 5.3: A Programming Language for a Growing Ecosystem

Six years after its initial launch, Swift is still in a fairly rapid development cycle, with a focus on stability and maturity. If you’re developing apps and services for iOS, macOS, and iPadOS, you’ll want to pay attention to its latest features and tooling—especially given the radical changes on Apple’s software roadmap. 

Ahead of the first ARM-based Macs—which many pundits believe will happen in November 2020—the Swift team seems to be emptying its cache in preparation for heightened developer activity across the ecosystem.  (If you’re new to the language, check out our previous short tutorials on functionsloopssetsarraysstructs and classes, and strings.)

Swift 5.3

With last year’s Swift 5, the language received some key milestone updates, including ABI stability. The more recent updates have been iterative, as you can imagine. “Swift 5.3 continues to focus on language refinements, the developer experience, and expanding the Swift ecosystem to enable more opportunities to write Swift,” says the team behind it. 

The mention of “opportunities” is telling. One common pain-point for developers writing Swift apps is the final product is often larger in size when compared to building in Objective-C, the aging programming language that Swift is meant to replace. The team notes that a Swift 4 binary is roughly 2.4-times the size of the same code written in Objective-C.

Swift 5.3 reduces that bloat. The team now claims version 5.3 is “under” 1.5 times the size of the same Objective-C code. The latest iteration also reduces heap use for memory optimization.

Code completion is improved, as well. When typing in Xcode, the team says both quality and speed of code completion is 15 times better, with improved indentation. Version 5.3 has improved compile time, too; a blog post notes three core improvements: 

  • Better identification of unchanged code (which won’t be re-compiled). 
  • Better correctness for declaration order and nesting. 
  • Faster compilation of code with external dependencies.

Windows Support

Apple has done a great job at improving the experience for writing applications for its own platforms. The ‘write once, deploy everywhere’ pipe dream is almost a walled-garden reality, and now the Swift team is making sure its roots reach under the wall and out into the open air.

Swift for Windows is still a project in development, but toolchain images are now available as a download. A blog post notes Visual Studio 2019 as well as CMake, Ninja, and the Windows SDK were necessary to build a simple calculator app… but the code is all Swift. It also holds tight to the Widows blocky UI; no “squircles” unless you really want them.

Swift for Windows also allows full access to libraries already available for Windows. Readdle, developers of the Spark email client, note how “pure Swift modules like CryptoSwift and OAuthSwift almost worked right out of the box” in a blog post on the topic. The Readdle team admits to creating some bespoke tooling for its project, but early returns are promising. It couches a full-throated endorsement of Swift for Windows at this time, while adding: “If you are maintaining a small Swift library, you could easily add Windows support already!”

Swift System

With a firmer grasp on user-facing platforms, Swift System hopes to stake a claim for low-level development. The Swift team calls it “a new library for Apple platforms that provides idiomatic interfaces to system calls and low-level currency types,” adding: “Our vision is for System to eventually act as the single home for low-level system interfaces for all supported Swift platforms.”

The idea is to avoid clumsy interoperability with the C programming language. “Most operating systems today support some flavor of system interfaces written in C that have existed for decades,” the Swift team writes. “While it is possible to use these APIs directly from Swift, these weakly-typed system interfaces imported from C can be error-prone and unwieldy,” suggesting there are stability issues that this open-source release addresses.

Notably, open system calls are static functions with pre-defined arguments, reducing your ability to make silly errors. System also uses strong types to catch compile-time errors, and throws errors using standard language mechanisms (which can’t be skipped). The cross-platform library has separate APIs for each platform it supports.

Atomics and Algorithms 

The all-new Swift Atomics is an interesting arrow added to the language’s quiver. The package allows for atomic operations within the code, so developers can build concurrent data structures within a codebase. Like any package, Atomics is imported to a codebase.

But unlike any other package, Atomics lets you bypass rules commonly governing Swift variables. As the team notes: “Atomic operations may be performed from multiple concurrent threads of execution, so long as the value is only accessed via atomic operations.”

Swift Algorithms is an open source algorithms package. It’s essentially algorithms popular in other programming languages, written in (and for) Swift. The example provided is called ‘chunked,’ which takes seemingly random collection types and allows a developer to parse them as needed. IT allows for things such as quick alphabetization of names in a collection. There are currently 11 algorithms in the package, with the implied hope that developers use those core algorithms to further define and develop their own. 

What It All Means

This is Swift everywhere, all the time. At the beginning of the year, Swift was an Apple-first language with some back-end tooling. The language is still Apple-first, but it’s now simpler for back-end developers, far more powerful on a code level, is starting to work for Windows, and has adopted core competencies that other languages have been using for years.

These are all early steps for Swift in new directions. Meanwhile, the language is still competing with Objective-C, which stubbornly refuses to die; it seems that entrenched Apple stalwarts have yet to fully embrace the newer language. Now we’ll watch to see if sever-side and Windows developers turn to Swift, too.