Playing in the big leagues now

Keep them coming: Swift 3.1 is out

Gabriela Motroc
Swift 3.1

Soccer field with sport light image via Shutterstock

Swift 3.1 is out. Although this is a minor language release, there are a few highlights worth mentioning.

Swift 3.0, the first major release of Swift since it was open-sourced was released six months ago so it’s time to bring it back into the spotlight. Swift 3.1 is out and even though it is a minor language release, there are a few highlights worth mentioning.

Swift 3.1 is source compatible with Swift 3.0 and contains a few language changes and updates, most of which went through the Swift Evolution process (once a proposal is refined and approved, it becomes a release goal, and is tracked as a feature of an upcoming version of Swift).

Swift 3.1 overview

New Sequence protocol members

The Sequence protocol now has two new members:

protocol Sequence {
  // ...
  /// Returns a subsequence by skipping elements while `predicate` returns
  /// `true` and returning the remainder.
  func drop(while predicate: (Self.Iterator.Element) throws -> Bool) rethrows -> Self.SubSequence
  /// Returns a subsequence containing the initial elements until `predicate`
  /// returns `false` and skipping the remainder.
  func prefix(while predicate: (Self.Iterator.Element) throws -> Bool) rethrows -> Self.SubSequence

Availability by Swift version

This version extends the @availability attribute to use the version of Swift to indicate the lifecycle of a declaration, according to the blog post announcing the release. As an example, an API that is removed in Swift 3.1 would be written as:

@available(swift, obsoleted: 3.1)
class Foo {

Deprecation and replacement of UnsafeMutablePointer.initialize(from:)

The version of UnsafeMutablePointer.initialize(from:) which takes a Collection has been deprecated in favor of a new method on UnsafeMutableBufferPointer which takes a Sequence with a aim of improving memory safety and enabling faster initialization of memory from sequences.

The Swift team has given a shout-out to IBM and other members of the community — version 3.1 contains many updates to the Linux implementation of Swift.

  • Implementation of NSDecimal
  • Implementation of NSLengthFormatter
  • Implementation of Progress
  • Many improvements to URLSession functionality, including API coverage and optimized usage of libdispatch
  • Improved API coverage in NSArray, NSAttributedString and many others
  • Significant performance improvements in Data. See more details here
  • Improved JSON serialization performance
  • Memory leaks fixed in NSUUID, NSURLComponents and others
  • Improved test coverage, especially in URLSession

Package manager updates

Package dependencies are now stored in the tool-managed build directory by default. A new swift package edit command allows users to “begin editing” on a package, moving it under the user’s control (into the Packages directory), exempting it from dependency updates, and allowing the user to commit and push changes to that package.

Furthermore, packages can now specify the minimum version of the Swift tools that they require. You cna edit the requirement with the swift package tools-version command; it is recorded at the top of the Package.swift manifest. Package versions which require newer Swift tools than those in use will be ignored by dependency resolution; therefore, packages can adopt new Swift features without breaking clients who are using older Swift tools.

The minimum tools version required determines which Swift language version is used to interpret the Package.swiftmanifest, and which version of the PackageDescription API is available.

Last but not least, packages can now specify whether their sources are written in the Swift 3 or Swift 4 language version. If not specified, a default is inferred from the Package’s minimum Swift tools version.

For more details about Swift 3.1, take a look at the Swift blog.

Swift 4 due date

Swift 4 should be completed in the fall of 2017. According to the blog post announcing the release process, version 4.0 “pivots around providing source stability for Swift 3 code while implementing essential feature work needed to achieve binary stability in the language.”

There will be significant enhancements to the core language and Standard Library, especially in the generics system and a revamp of the Stringtype.

It is worth mentioning that the difference between Swift 3 and Swift 4 code is expected to be much smaller than the jump from Swift 2.2 to Swift 3.

SEE ALSO: Trending on the charts: Swift hits Top 10 for popular programming languages

Swift is gaining momentum

It’s official. TIOBE released their latest index and for the first time, Swift has cracked the top ten programming languages list. It’s a tossup whether Swift will be able to rise up much further on this list. For one thing, the language is limited to the Apple ecosystem. However, some companies like IBM are considering using Swift as a server-side language, if only because of the speed and small memory requirements. That makes Swift theoretically cheaper than Java to run at scale on cloud infrastructure.

Plus, it’s still hard as all get out to use Swift on Android systems. When asked whether developers could write Android applications in Swift, Google bluntly responded, “No.”

Gabriela Motroc
Gabriela Motroc was editor of and JAX Magazine. Before working at Software & Support Media Group, she studied International Communication Management at the Hague University of Applied Sciences.

Inline Feedbacks
View all comments