Apple’s Swift language will get a new open source Foundation framework – used in almost all Swift projects – that will be native Swift, rather than wrapping Objective-C as it does currently.
Tony Parker, a senior software engineering manager at Apple who works on Swift packages, introduced the new project last month. Foundation is a “base layer of functionality for apps and frameworks,” covering fundamental types, collections, date and time utilities, file APIs, process and thread management, errors and exceptions, and more.
Apple has implemented Foundation in Objective-C for Apple platforms, but when Swift was made open source in 2016 an implementation for other platforms was needed. As Apple explained here: “A significant portion of the implementation of Foundation on Apple platforms is provided by another framework called CoreFoundation,” which is written in C and “very portable,” so this code was used where possible in the open source, cross platform version.
The new Foundation project will be done differently. “Today, we are announcing a new open source Foundation project, written in Swift, for Swift,” said Parker. This will improve performance because “conversion costs” between C and Swift will be removed. There will also be more granular packages, a new FoundationEssentials package with no system dependencies, a separate FoundationInternationalizion package, and a new FoundationObjCCompatibility package.
The launch of the new framework will be “on GitHub in 2023,” said Parker.
The Swift community is positive about the news. “Just wanted to post a short positive note as someone who explicitly has avoided Foundation (for all the known reasons) – this looks like an excellent pragmatic approach,” said one developer.
One common question is how the new project will relate to Foundation on Apple operating systems. It seems that it will be somewhat distinct. “Darwin Foundation (what we will call ‘Foundation framework’ to distinguish it) will be a superset of the package, because it will include all of the implementations we cannot remove or refactor as part of this work (stuff written in Objective-C or which we decide to omit from the package for some reason),” said Parker. He also said “the existing swift-corelibs-foundation repository will continue to exist,” in case it is needed for compatibility. When compiling for Apple systems, there will be an option to use either the Swift or the Darwin version.
“Darwin” is the base of macOS, iOS and other Apple operating systems. The uname command on the latest macOS Ventura, for example, returns “Darwin Kernel Version 22.2.0”.
A native Swift implementation of Foundation will be good for the language, which is still perceived as mainly for Apple systems. Swift has settled at around 11th place in the Redmonk Programming Language Rankings, and shows little sign of growth other than versus Objective-C which it has overtaken. “If or when it is ever established as a server side language as IBM and others have attempted to push at times, its ceiling is virtually unlimited,” said Redmonk analyst Stephen O’Grady in 2018, but that has not happened.
“Swift is already a really strong language albeit a little too tied to Apple’s ecosystem. This along with the ownership manifesto slated for Swift 6 (and C++ interop) should make it easier to use it everywhere,” remarked a developer on Hacker News. Others said the language has much in common with Rust in terms of safety and performance, but is easier to use. There is a sense that Swift still has unrealized potential in the industry, beyond its use for programming Apple applications, but whether that will change remains an open question.