Apple tailors Swift System library for open source and Linux support

Multi-platform not cross-platform, says company – enough to increase interest in the language?

Apple has open-sourced Swift System, a library designed to improve the experience of calling the operating system API from Swift on supported platforms, including a new Linux implementation.

Swift System was introduced in June for Apple platforms only, and is an alternative to importing C interfaces directly, where the developer has to deal with unmanaged pointers and other intricacies which Swift normally avoids. Swift System makes these interfaces available but wrapped so that they behave like native Swift functions.

Apple engineer Michael Ilseman said that the company is "open-sourcing System and adding Linux support". The goal is "for System to eventually act as the single home for low-level system interfaces for all supported Swift platforms". It is intended as multi-platform rather than cross-platform, meaning that System has separate APIs for each platform so developers still need to use conditional preprocessor directives like #if in cross-platform code.

There is a long way to go. The code published on GitHub is small and mainly covers just a few file-handling APIs. Ilseman is not impressed by some aspects of Linux, commenting in LinuxPlatformConstants.swift: "Ugh, this is really bad. For Darwin, we can at least rely on these values not changing much, but in theory they could change per Linux flavor or version (if no ABI)."

Another big issue is Windows, which is more challenging since it is not a Unix-like operating system. Ilseman made the best of it, saying: "System (especially the forthcoming Windows support!) is a fantastic opportunity to get involved in the Swift project."

Swift has hardly taken off as a cross-platform language, despite Linux support, and most usage is to replace Objective-C for developing on Apple platforms. The language is well regarded, but there is competition from alternatives like Go and Dart, as well as old stalwarts C++ and C. IBM's support for server-side Swift ran into the buffers late in 2019. The result is that Swift, having grown rapidly in popularity in its early days thanks to productivity and performance advantages over Objective-C, has stalled, ranking at 11 on Redmonk's popularity index for the last three iterations.

In this context, Apple's efforts to improve support on other platforms, including its forthcoming Windows support, looks like an attempt to revive interest in Swift outside the Apple bubble, and for Apple platform developers porting applications to other targets. However, a problem is that SwiftUI, the GUI framework that is among the most compelling reasons to use Swift, is Apple-platform only.

It is easy to make announcements, less easy to build a multi-platform community. ®

Biting the hand that feeds IT © 1998–2020