AWESOME: Test Collection

What’s new in Apple’s Swift 4.2 language

The programming language for MacOS and iOS apps offers an improved package manager, new source-code compatibility option, and many language improvements

What’s new in Apple’s Swift 4 language
Stefan Berndtsson (CC BY 2.0)

Between the September 2017 release of Swift 4 and the planned fall 2018 release of Swift 5, Apple is working on intermediate versions to smooth the transition.

Next version: Key features in Apple’s Swift 4.2

The planned 4.2 release of Apple’s Swift language is focused on stabilizing the language’s ABI (application binary interface). Swift 4.2 will serve as an intermediary step to achieving ABI stability in the planned Swift 5.0 release due late this year. ABI stability allows for binary compatibility between applications and libraries compiled with different Swift releases.

ABI changes in Swift 4.2, many of which tie into performance, are to be rolled out incrementally so there can be time for user feedback before changes are locked into place in the ABI.

Although Apple’s goal is stability, Swift 4.2 is not binary-compatible with previous releases. Source compatibility, however, is planned. Most source code built with the Swift 4.0 compiler should compile with the Swift 4.2 compiler and the Swift 4.1 compiler.

Other plans for Swift 4.2 include improvements to compile-time performance and numerous bug fixes.

The final branching for Swift 4.2, with changes merged into the master for the last time, is planned for April 20. Afterwards, a “bake” period will follow in which only some critical fixes will be put into the release.

Where to download snapshots of Swift 4.2

Swift 4.2 snapshots will be posted on as part of integration testing.

Current version: What’s new in Swift 4.0

Swift 4.0 is a major upgrade to Apple’s Swift, the three-year old successor to the Objective-C language used for MacOS and iOS application development.

The Swift 4 upgrade enhances the Swift Package Manager and provides new compatibility modes for developers. Apple said Swift 4 also makes Swift more stable and improves its standard library. Swift 4 is largely source-compatible with Swift 3 and ships as part of Apple’s Xcode 9 IDE.

What’s new in Swift 4’s package manager

Swift Package Manager, which debuted in Swift 3, is tool for distributing code. It is integrated with the Swift build system to automate processes including downloading, compiling, and linking of dependencies. Improvements in Swift 4’s package manager include:

  • A cleaner Package API that allows packages to specify new settings. These settings give developers more control over the building of packages and organization of sources on disk.
  • Development of multiple packages in tandem has been made easier.
  • Formalization of package products, enabling control over what libraries a package publishes to clients.
  • Package builds on MacOS now occur in a sandbox, preventing network access and file-system modification, to reduce the reach of malicious manifests.

New compatibility modes in Swift 4 aid migration

Swift 4’s new compatibility modes could save you from having to modify code to be able to use the new version of the compiler. Two modes are supported, including the Swift 3.2 mode, which accepts most source files built with Swift 3.x compilers, and the Swift 4.0 mode, which includes Swift 4 and API changes.

Apple said that some source migration will be needed for many projects, but the number of source changes are “quite modest” compared to many previous major changes between Swift releases. The introduction of the compatibility modes in Swift 4 gives developers more control over the pace of migration.

Language improvements abound in Swift 4

Swift 4 introduces several language improvements, including:

  • A faster and easier-to-use String implementation retaining Unicode correctness and supporting development and use of substrings.
  • Improved use and management of Collection types.
  • Enforcement of exclusive access to memory, in which potential modifications of variables must be exclusive with any other access to that variable.
  • Ability to archive struct and enum types.
  • Type-safe serialization to external formats such as JSON.
  • Protocol-oriented integers, which cleans up Integer APIs and making them more useful for generic programming.
  • Support of where clauses to constrain associated types. Previously, associated types could express only simple inheritance constraints and not more sophisticated constraints available to generic types with the where clause.
  • Inclusion of the swift run command to build and run an executable defined in the current package.
  • Removal of final keyword support when declaring functions in protocol extensions.
  • Improved interaction between private declarations and extensions, with private access control extended so members defined in an extension of a type have the same access as members defined on the type itself, as long as the type and extension are in the same source file.

This story, "What’s new in Apple’s Swift 4.2 language" was originally published by InfoWorld.

ITWorld DealPost: The best in tech deals and discounts.
Shop Tech Products at Amazon