Swift 4.0 is now available. It's 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
Stringimplementation 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
- 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
whereclauses to constrain associated types. Previously, associated types could express only simple inheritance constraints and not more sophisticated constraints available to generic types with the
- Inclusion of the
swift runcommand to build and run an executable defined in the current package.
- Removal of
finalkeyword support when declaring functions in protocol extensions.
- Improved interaction between
privatedeclarations and extensions, with
privateaccess 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.
Sign up for Computerworld eNewsletters.