On March 25 Swift 5 was released. It marked a major milestone in Swift language evolution, mostly by ABI stability. This update is more about building blocks and fundamentals for future version. But it also gives us a few language improvements. Some of them were long-awaited. Also Swift Package Manager wasn’t left untouched.
In this part we will focus on ABI stability and SPM updates, while part 2 will take in-deep tour along Swift 5 language improvements.
So let’s dive in this and: “Say hi to Swift 5”!
Since first news about Swift 5 we heard about ABI stability. But what is this mysterious acronym?
Quick jump to Wikipedia and we got ours answers:
In computer software, an application binary interface (ABI) is an interface between two binary program modules; often, one of these modules is a library or operating system facility, and the other is a program that is being run by a user.
So what that means for Swift and Apple’s world?
Simply, this and all of future releases of Swift libraries will be included into Apple’s platform operating systems: macOS, iOS, tvOS and watchOS. What is more important, compatibility between apps and libraries compiled with different Swift versions will be ensured on binary level. This also means that apps will take a bit less space as standard library will be embedded into operation system. On other hand OS will take more space as those libraries must be put somewhere.
In the example above an app is built with Swift 5, so it will run on every system with Swift 5 library installed. When future release of Swift 5.1 or Swift 6 arrives, the app will also run on those systems. For now app build with Swift 4.2 will not run on Swift 5. It must be built and compiled again for new release.
Swift Package Manager Updates
There are three new things for SPM in Swift 5:
• Platform deployment settings SE-0236
• Target specific build settings SE-238
• Dependency mirroring SE-0219
SE-0236 gives us ability to define minimum required deployment target version in our Package.swift file.
// SWIFT let package = Package(name: “Say Hi to Swift 5”, platforms: [ .macOS(.v10_14), .iOS(.v12), .tvOS(.v12), .watchOS(.v5) ])
All supported deployment targets are used in snippet above. Previously we had hardcoded only macOS values.
Target specific build settings proposal, as its name says, allows us to use and specify some target build settings, for example linking C++ frameworks. It’s a small improvement on way to achieve more complex build settings model in Swift Package Manager.
SE-0219 proposal introduces dependency mirror feature to SPM, which allows to refer to alternate source location which *drum roll* mirror the original source. It’s quite useful for cases like caching or availability concerns – if original source is not available or access to it could be slow, it takes mirrored source.
Lastly Swift 5 brings coverage data gathering to the SPM.
That will be all for part 1 of the Say Hi to Swift 5 tour, but don’t worry – there is more to come!
In the next (and final) part we will look at crème de la crème of Swift 5 – language improvements. But before we go further – what do you think ABI stability will bring to Swift? Is it as huge milestone as they say?