Along with this week’s launch of iOS 11 came another big step for Apple’s mobile ambitions: Swift 4 has been officially released, and brings some interesting changes and additions, along with one glaring omission.
One key feature in Swift 4: strings have been re-imagined with speed and ease in mind. As the Swift team writes in its official blog posting about the release, it has “implementation that retains Unicode correctness and adds support for creating, using and managing substrings.” This includes a new literal for multi-line strings, too. Developers can now declare a triple-quote (“””) for paragraphs and other, longer text. Here’s an example:
let multilineString = “””
Multiple lines of text.
Developers can even use “quotes” in-line.
String interpolation works, too: 3 * 3
The closing triple-quote delimiter
Version 4.0 is also backwards-compatible with Swift 3.2, allowing developers to update modules as they see fit and continue using open-source libraries that may not have migrated yet.
Collections have also been tweaked. A new
swapAt function lets you quickly rearrange items in an array. The existing
swap( _: _: ) function will no longer work. Dictionaries and Set enhancements will allow for dictionary creation from sequenced key-value pairs, merging duplicate keys and a default for returning values on missing keys.
The package manager comes with all the Swift 4 APIs, which will be sandboxed on macOS. As the Swift team writes, it “prevents network access and file system modification, to help mitigate the effect of maliciously crafted manifests.” A new Package API lets packages specify new settings, giving authors more control over how they build.
The missing piece? Application Binary Interface (ABI) stability. The team has published a ‘manifesto’ outlining how it plans to get there, and a dashboard so developers can see where and when Swift ABI features stand in the grand scheme. We can get an idea of why ABI stability has eluded Swift, which is described as “Objective-C without the C.” From the manifesto:
Most platform vendors define a “standard ABI” which is used for C code and built on by C-family languages. Swift, however, is a very different language from C and has its own per-platform ABI.
This should arrive in Swift 5, though we’ll have to wait a full year for that to drop.